Workers Cron Feedback

I did a little playing around with Workers Cron today, here’s a few things that came up:

  1. Console.log doesn’t get streamed to wrangler tail, which would be very helpful for developing and debugging a cron.
  2. It seems like adding a cron doesn’t take effect immediately, but takes 3-5 minutes to enable? Without a console.log and with a delay, it can make iterating on a worker in progress a bit challenging.
  3. It would be nice to be able to define/update the cron in the wrangler.toml

Other than those 3 things, everything worked pretty flawlessly.

Because of the lack of console.log in a cron worker, I suggest building all the logic in a regular worker and then migrate it to a cron after it works.

With regards to 3, this is possible with Wrangler 1.12! You can define crons with a triggers table and a crons array like so:

name = "scheduled"
type = "javascript"

[triggers]
crons = ["* * * * *"]
2 Likes

Ok, I’m a bit weak on my toml skills, but how do I set these on an environment level?

this didn’t work:

[env.test]
...
[env.test.triggers]
crons = ["* * * * *"] 

oh shoot, this does work I just had an older version of wrangler.

Leaving this here in case anyone else needs to know how to do this.

You can also do

[env.test]
...
triggers.crons = ["*/10 * * * *"]