Skip to content
Workers
Visit Workers on GitHub
Set theme to dark (⇧+D)

ScheduledEvent

Background

The event type for Scheduled requests to a Worker. The Object passed through as event in addEventListener().

Context

addEventListener("scheduled", event => {  event.waitUntil(handleScheduled(event))})

Properties

  • event.type string

    • The type of event. This will always return "scheduled".
  • event.scheduledTime number

    • The time the ScheduledEvent was scheduled to be executed in milliseconds since January 1, 1970, UTC. It can be parsed as new Date(event.scheduledTime)

Methods

When a Workers script is invoked by a Cron Trigger, the Workers runtime starts a ScheduledEvent which will be handled by the event listener registered for the type "scheduled". The event handler can invoke the following methods of the event object to control what happens next:

  • event.waitUntil(promisePromise) void
    • Use this method to notify the runtime to wait for asynchronous tasks (e.g. logging, analytics to third-party services, streaming and caching). The first event.waitUntil to fail will be observed and recorded as the status in the Cron Trigger Past Events table. Otherwise, it will be reported as a Success.