diff options
| author | akiyamn | 2023-09-24 23:22:21 +1000 |
|---|---|---|
| committer | akiyamn | 2023-09-24 23:22:21 +1000 |
| commit | 4e87195739f2a5d9a05451b48773c8afdc680765 (patch) | |
| tree | 9cba501844a4a11dcbdffc4050ed8189561c55ed /src/index.ts | |
| download | price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip | |
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..674339b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,50 @@ +/** + * Welcome to Cloudflare Workers! + * + * This is a template for a Scheduled Worker: a Worker that can run on a + * configurable interval: + * https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/ + * + * - Run `npm run dev` in your terminal to start a development server + * - Open a browser tab at http://localhost:8787/ to see your worker in action + * - Run `npm run deploy` to publish your worker + * + * Learn more at https://developers.cloudflare.com/workers/ + */ + +export interface Env { + // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/ + // MY_KV_NAMESPACE: KVNamespace; + // + // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/ + // MY_DURABLE_OBJECT: DurableObjectNamespace; + // + // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/ + // MY_BUCKET: R2Bucket; + // + // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/ + // MY_SERVICE: Fetcher; + // + // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/ + // MY_QUEUE: Queue; + // + // Example binding to a D1 Database. Learn more at https://developers.cloudflare.com/workers/platform/bindings/#d1-database-bindings + // DB: D1Database +} + +export default { + // The scheduled handler is invoked at the interval set in our wrangler.toml's + // [[triggers]] configuration. + async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> { + // A Cron Trigger can make requests to other endpoints on the Internet, + // publish to a Queue, query a D1 Database, and much more. + // + // We'll keep it simple and make an API call to a Cloudflare API: + let resp = await fetch('https://api.cloudflare.com/client/v4/ips'); + let wasSuccessful = resp.ok ? 'success' : 'fail'; + + // You could store this result in KV, write to a D1 Database, or publish to a Queue. + // In this template, we'll just log the result: + console.log(`trigger fired at ${event.cron}: ${wasSuccessful}`); + }, +}; |
