CRON scheduled event more data

Currently, the CRON scheduled event contains the following properties:

  • cron - the CRON expression
  • type - always equal to "scheduled"
  • scheduledTime - the time in miliseconds

As CRONs are often used to fetch some external data, they might be a subject to a flood of new data if they run for the very first time, for example: a deployment to a new environment that needs to catch up with all the data. When looking at the dashboard, triggers, one can see the list of recent runs that is obtained using GraphQL. At the same time CRON cannot measure its execution internally, as it’s a subject to the sandboxing security mechanism, which sets the date as const for any given execution.

It would be great if the scheduled event contained the last run time. It would allow to create adaptive CRONs that understood how long they were running without breaching the sanbox. Would it be possible to have it added dear CF team?

  • You could do it yourself pretty easily with a Durable Object
  • will advance after you await on some i/o. Try making a simple fetch call at the end of your cron execution - maybe, again, to a DO

The CRON is issuing tens of IOs. That’s why I was asking about having it embedded in the event. If the time and, let’s say, status of the last one are ok, I could do a bit more in the 30s Unbound grant.

The solution that I applied is based on adding a query to endpoint for analytics. This allows me to query historical data and apply an adaptive approach on the recent execution times and statuses. I’m aware that analytics provide data not in real time. This is sufficient though to make the process adaptive.

That’s a cool idea. You are querying the workersInvocationsScheduled dataset?

That’s correct! The only disadvantage that I found so far is that I have to pass the worker name as scriptName env variable as it’s not accessible through globals. Again, it’d be a great advantage if events, either fetch or scheduled provided a bit more context. But anyway, it works and already proved itself in the production :grinning_face_with_smiling_eyes:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.