Skip to content

Cloudflare cron triggers documentation does not include code sample #20632

@thomas-desmond

Description

@thomas-desmond

Proposed changes

Please assign me to this issue.

Add the following code sample to the page to highlight the scheduled function required for cron triggers in Workers.

export default {
    async fetch(request, env, ctx): Promise<Response> {
        return new Response('Hello World!');
    },
    
    /**
     * This function is triggered by a Cloudflare Cron Trigger.
     * It runs at specified intervals to perform scheduled tasks.
     */
    async scheduled(event, env, ctx): Promise<void> {
        // Example scheduled task: Log the current date and time
        const currentTime = new Date().toISOString();
        console.log(`Scheduled task executed at: ${currentTime}`);
    }
} satisfies ExportedHandler<Env>;

Subject Matter

Workers cron triggers

Content Location

Additional information

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions