diff --git a/src/content/docs/containers/examples/cron.mdx b/src/content/docs/containers/examples/cron.mdx index ac982fedd20994..5a06cb41d5acbd 100644 --- a/src/content/docs/containers/examples/cron.mdx +++ b/src/content/docs/containers/examples/cron.mdx @@ -54,31 +54,34 @@ Use a cron expression in your Wrangler config to specify the schedule: Then in your Worker, call your Container from the "scheduled" handler: ```ts -import { Container, getContainer } from "@cloudflare/containers"; +import { Container, getContainer } from '@cloudflare/containers'; export class CronContainer extends Container { - sleepAfter = "5m"; + sleepAfter = '10s'; + + override onStart() { + console.log('Starting container'); + } + + override onStop() { + console.log('Contianer Stopped'); + } } export default { - async fetch(): Promise { - return new Response( - "This Worker runs a cron job to execute a container on a schedule.", - ); - }, + async fetch(): Promise { + return new Response("This Worker runs a cron job to execute a container on a schedule."); + }, - // scheduled is called when a cron trigger fires - async scheduled( - _controller: any, - env: { CRON_CONTAINER: DurableObjectNamespace }, - ) { - await getContainer(env.CRON_CONTAINER).startAndWaitForPorts({ - startOptions: { - envVars: { - MESSAGE: "Start Time: " + new Date().toISOString(), - }, - }, - }); - }, + async scheduled(_controller: any, env: { CRON_CONTAINER: DurableObjectNamespace }) { + let container = getContainer(env.CRON_CONTAINER); + await container.start({ + envVars: { + LOCATION: "The Cloudflare San Francisco Office", + LATITUDE: "37.780259", + LONGITUDE: "-122.390519", + } + }) + }, }; ```