cloudworker icon indicating copy to clipboard operation
cloudworker copied to clipboard

Add support to Cloudflare Worker scheduled event

Open EricxStone opened this issue 4 years ago • 0 comments

Background

Cloudflare has added the support of their worker to be triggered by scheduled event. These workers are triggered on the cron schedule setup on Cloudflare Worker dashboard. They are implemented with an event listener to scheduled event instead of fetch in traditional worker. This causes the test with Cloudworker impossible.

Enhancement

Add the support of scheduled event to Cloudworker, where developers can mock the trigger of the worker. The usage of such worker will become

const Cloudworker = require('@ericxstone/cloudworker')

const simpleScript = `addEventListener('scheduled', event => {
  event.waitUntil(() => {});
})`

const cw = new Cloudworker(simpleScript)
cw.triggerCronJob.then((res) => {
  console.log("Schedule is triggered")
})

EricxStone avatar Aug 30 '21 11:08 EricxStone