jplhomer / superflare

A full-stack toolkit for Cloudflare Workers.
https://superflare.dev
765 stars 22 forks source link

Adding cron jobs support #18

Closed omarkhairy21 closed 1 year ago

omarkhairy21 commented 1 year ago

Hey, @jplhomer thanks for that awesome work i was struggling to build my abstraction around the Cloudflare stack but you did an amazing job!

I am wondering if there is a plan to support Cron jobs. Also, i am ready to contribute to this.

jplhomer commented 1 year ago

I would love this!

One challenge:

Proposed API

// worker.ts

export default {
  async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext) {
    await handleScheduled(event, env, ctx, (schedule: Schedule) => {
      schedule.run(async () => {
        // some bespoke function
      }).dailyAt('8:00').timezone('America/New_York');

      schedule.job(new MyJobClass(my, args)).weekly();

      // ...
    });
  },
}
jplhomer commented 1 year ago

How does this sound? https://github.com/jplhomer/superflare/issues/18

omarkhairy21 commented 1 year ago

Sounds Great! thanks for that huge effort I left a comment with just one concern on the pull request

omarkhairy21 commented 1 year ago

BTW that pull request and your comment inspired me to create a cron toolkit library to create cron expressions with human-readable functions also with type safety

jplhomer commented 1 year ago

@omarkhairy21 That's awesome!