@miniflare/scheduler
TypeScript icon, indicating that this package has built-in type declarations

2.14.4 • Public • Published

@miniflare/scheduler

Scheduler module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers. See ⏰ Scheduled Events for more details.

Example

import { CorePlugin, MiniflareCore } from "@miniflare/core";
import { VMScriptRunner } from "@miniflare/runner-vm";
import { Log, LogLevel } from "@miniflare/shared";
import { SchedulerPlugin, startScheduler } from "@miniflare/scheduler";
import { MemoryStorage } from "@miniflare/storage-memory";

export class BadStorageFactory {
  storage() {
    throw new Error("This example shouldn't need storage!");
  }
}
const plugins = { CorePlugin, SchedulerPlugin };
const ctx = {
  log: new Log(LogLevel.INFO),
  storageFactory: new BadStorageFactory(),
  scriptRunner: new VMScriptRunner(),
};

const mf = new MiniflareCore(plugins, ctx, {
  modules: true,
  script: `export default {
    async scheduled(request, env) {
      console.log("tick");
    }
  }`,
  crons: ["* * * * *"],
});

const scheduler = await startScheduler(mf); // tick, tick, tick, ...
scheduler.dispose();

Package Sidebar

Install

npm i @miniflare/scheduler

Weekly Downloads

33,440

Version

2.14.4

License

MIT

Unpacked Size

11.4 kB

Total Files

5

Last publish

Collaborators

  • wrangler-publisher