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 support for cron triggers #104

Closed
wants to merge 7 commits into from

Conversation

Randoooom
Copy link

Adds support for cron triggers (resolves #53).

I currently need some inspiration for handling an undefined scheduled event in the shim.mjs

@Randoooom Randoooom changed the title Feat/cron/scheduled Add support for cron triggers Dec 28, 2021
@nilslice
Copy link
Contributor

@Randoooom - this is great, thank you for working on adding scheduled event triggers.

I think we should still include waitUntil in the API, but it will require updating more code to include the ctx object into the function signature. I'd suggest taking a look at the docs for this function: https://developers.cloudflare.com/workers/runtime-apis/scheduled-event#syntax-module-worker

It might seem more complicated at first glance with the old implementation in workers-rs since it was leftover from a prior implementation where the EventListener format vs. modules

Let me know if you have any specific request for guidance or commentary on this while its in review. You can also join us on our Discord: https://discord.com/invite/cloudflaredev, where the team can more continuous conversation with you.

@Randoooom
Copy link
Author

Oh yea, now I see I might be very stupid: I already implemented waitUntil but instead of using ctx I used the root object. I will keep working on it

@nilslice
Copy link
Contributor

Not stupid at all - this is impressive work! Keep at it, and let me know how we can help.

@Randoooom
Copy link
Author

Just resolved the generation of the shim.mjs.
I'm not sure if there is a better variant, but this is working at the moment:

    let shim_content = format!(
        r#"
import * as imports from "./{0}.mjs";

const fetch = imports.fetch;
const scheduled = imports.scheduled;

export * from "./{0}.mjs";
export default {{ fetch, scheduled }};
"#,
        bg_name
    );

@Randoooom Randoooom marked this pull request as ready for review January 11, 2022 14:22
Copy link
Collaborator

@zebp zebp left a comment

Choose a reason for hiding this comment

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

Error handling for wait_until should be improved.

worker/src/schedule.rs Show resolved Hide resolved
worker/src/schedule.rs Show resolved Hide resolved
@zebp
Copy link
Collaborator

zebp commented Jan 20, 2022

During my process of fixing this merge conflict, I accidentally managed to squash your commits. But this has been merged, thank you @Randoooom.

@zebp zebp closed this Jan 20, 2022
@zebp zebp mentioned this pull request Jan 20, 2022
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.

scheduled event failed
3 participants