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

Add JS-friendly API for specifying Deno.cron schedule #21122

Closed
igorzi opened this issue Nov 8, 2023 · 12 comments
Closed

Add JS-friendly API for specifying Deno.cron schedule #21122

igorzi opened this issue Nov 8, 2023 · 12 comments
Assignees
Labels
ext/cron good first issue Good for newcomers help wanted community help requested

Comments

@igorzi
Copy link

igorzi commented Nov 8, 2023

Currently Deno.cron() 2nd argument is a string, which specifies the schedule using the cron format.

We'd like to extend this with a JS-friendly API, which allows the schedule to be specified using Javascript object literals. The conversion should happen in https://github.com/denoland/deno/blob/main/ext/cron/01_cron.ts.

Here are some examples:

Exact

Deno.cron("cron", "1 * * * *", ..);

becomes:

Deno.cron("cron", { minute: { exact: 1 } }, ..);
// Or
Deno.cron("cron", { minute: 1 }, ..);

Every nth

Deno.cron("cron", "0 7/2 * * *", ..);

becomes:

Deno.cron("cron", { minute: 0, hour: { start: 7, every: 2 } }, ..);

List of schedules

Deno.cron("cron", "0 0 * * 1,3,5", ..);

becomes:

Deno.cron("cron", { minute: 0, hour: 0, dayOfWeek: [ 1, 3, 5] }, ..);
@igorzi igorzi added good first issue Good for newcomers help wanted community help requested ext/cron labels Nov 8, 2023
@Cedar-81
Copy link

I would like to handle this issue if it's okay by you. Still a beginner to open source though but I feel like I can try it out

@Cedar-81
Copy link

While I wait to be assigned to this issue, I'd like to say I am currently working on this for anyone who might want to hop on as well. Thanks

@igorzi
Copy link
Author

igorzi commented Nov 10, 2023

Thanks @Cedar-81

@Cedar-81
Copy link

Quick questions can you give more information about the schedule string, you've stated that it can accept minute, hour, date_of_week, but there are 2 asterisks left. If there is any resource I can use to understand the schedule string better it would be really helpful cause I'd need to reconstruct the schedule string from the passed in object so I need to understand its format.

@igorzi
Copy link
Author

igorzi commented Nov 10, 2023

It's a standard cron schedule string. See https://en.wikipedia.org/wiki/Cron.

@Cedar-81
Copy link

okay, thanks.

@fightbulc
Copy link

on a side note there is a npm package which helps to abstract that string:
https://www.npmjs.com/package/cron-time-generator

@raashidanwar
Copy link
Contributor

raashidanwar commented Nov 24, 2023

I want to pick this task @igorzi.

Where exactly are we writing test cases for corn?

@igorzi
Copy link
Author

igorzi commented Nov 25, 2023

Sounds good, @raashidanwar! Please check with @Cedar-81.

Current cron tests are here: https://github.com/denoland/deno/blob/main/cli/tests/unit/cron_test.ts

@Cedar-81
Copy link

Sorry for not attending to this for so long, funny enough I have actually implemented this but I couldnt run tests because I had some problems setting up Rust and according to the Docs I needed to run all tests.

Feel free to go ahead as I am currently swamped with some other tasks. Thanks a lot for this opportunity and sorry again for not reaching out for so long.

@raashidanwar
Copy link
Contributor

Hi @igorzi 👋 .

Here is the draft PR #21340. Do have a look.
I tried writing the test cases, but when I am running it using ./target/debug/deno test --unstable --allow-env cli/tests/unit/cron_test.ts somehow, it gave a type error that only string is expected, but I have tested it with a dummy code, and it is correctly parsing the JSON.
would be glad if you could help it the test case issue.

@raashidanwar
Copy link
Contributor

@igorzi I added the test cases. Do have a look at PR #21340.

@igorzi igorzi closed this as completed in ab755a0 Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext/cron good first issue Good for newcomers help wanted community help requested
Projects
None yet
Development

No branches or pull requests

4 participants