Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cron) implement Deno.cron() #21019

Merged
merged 7 commits into from
Nov 1, 2023
Merged

feat(cron) implement Deno.cron() #21019

merged 7 commits into from
Nov 1, 2023

Conversation

igorzi
Copy link
Contributor

@igorzi igorzi commented Oct 30, 2023

This PR adds unstable Deno.cron API to trigger execution of cron jobs.

  • State: All cron state is in memory. Cron jobs are scheduled according to the cron schedule expression and the current time. No state is persisted to disk.
  • Time zone: Cron expressions specify time in UTC.
  • Overlapping executions: not permitted. If the next scheduled execution time occurs while the same cron job is still executing, the scheduled execution is skipped.
  • Retries: failed jobs are automatically retried until they succeed or until retry threshold is reached. Retry policy can be optionally specified using options.backoffSchedule.

Comment on lines +4569 to +4577
[[package]]
name = "saffron"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03fb9a628596fc7590eb7edbf7b0613287be78df107f5f97b118aad59fb2eea9"
dependencies = [
"chrono",
"nom 5.1.3",
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is saffron maintained anymore? cloudflare/saffron#20

Anyways, we should ask saffron to upgrade to nom 7.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confirmation that Cloudflare is happy to merge PRs, as it is still in use at CF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@littledivy can we do this after this PR is landed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link

@Hexagon Hexagon Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on an alternative to saffron that might be of interest - with second granularity and support for timezoned DateTimes. Also nicknames for @hourly. Extended syntax like L for last occurrence of weekday in month. Standards-compliant weekday entry (1 is monday, in saffron 0 seem to be monday). Early stuff, started yesterday, and (disclaimer) my first Rust project ever, but starting to look like something - https://crates.io/crates/croner/0.0.3 https://github.com/hexagon/croner-rust

Copy link

@Hexagon Hexagon Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try {
assertThrows(
() => Deno.cron("abc", "*/20 * * * *", () => {}),
"Invalid cron name",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a different error message, Invalid cron name for a duplicate name is confusing - e.g. a dependency of dependency registers a cron and suddenly you get this error in your own code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this test is wrong. 2nd arg to assertThrows should be the exception type. I'll fix the tests and make sure that it's checking for the correct error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@igorzi igorzi requested a review from losfair November 1, 2023 18:12
Copy link
Member

@losfair losfair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@igorzi igorzi merged commit 01d3e0f into main Nov 1, 2023
13 checks passed
@igorzi igorzi deleted the deno_cron2 branch November 1, 2023 18:57
@igorzi igorzi restored the deno_cron2 branch November 1, 2023 22:30
@igorzi igorzi deleted the deno_cron2 branch January 4, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants