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

Support cron triggers using preview and dev #570

Closed
Kynson opened this issue May 31, 2021 · 3 comments · Fixed by #1815 or #1860
Closed

Support cron triggers using preview and dev #570

Kynson opened this issue May 31, 2021 · 3 comments · Fixed by #1815 or #1860
Labels
enhancement New feature or request

Comments

@Kynson
Copy link

Kynson commented May 31, 2021

💡 Feature request

Describe the feature

Currently, there is no way to test scheduled jobs, since we can't fire a scheduled during development. I suggest adding support of "cron triggers testing" for wrangler dev or wrangler preview, which speeds up the development and testing.

Possible methods of triggering a cron job during development:

  • For wrangler dev, wrangler creates a special route (path) during development, and developers can trigger a job by sending a request to the route, eg: GET http://127.0.0.1:8787/__crons/:cronExpression
  • For wrangler preview, a Test Triggers tab is available for developers to trigger a cron job.

Describe the alternatives

The current work around for this issue is to simply deploy the worker to production.
Or add the code I want to test to the fetch event handler, which is really inconvenient:

addEventListener('scheduled', (event) => {
  event.waitUntil(scheduledJob(event))
});
addEventListener('fetch', (event) => {
  event.respondWith(scheduledJob(event))
})
const scheduledJob = (event) => {
  // Job
}

Thanks.

@Kynson Kynson added the feature label May 31, 2021
@Electroid
Copy link
Contributor

Thanks for making this issue! This is definitely something we need to support.

In the interim, a simple workaround would be to call a mock scheduled event from a fetch handler. Not nice, but it can get the job done for you if you need it today.

@Electroid Electroid changed the title [Feature Request] Cron triggers for Local Development Support cron triggers using preview and dev Jun 3, 2021
@Kynson
Copy link
Author

Kynson commented Oct 11, 2021

Cloudflare recently released miniflare, which supports cron trigger testing. If anyone wants to test cron triggers at the moment, you may refer this link https://miniflare.dev/scheduled.html

Of cause, cron trigger support for wrangler dev/wrangler preview would also be appreciated

@threepointone
Copy link
Contributor

Copy pasting from #738 (comment), where we're landing support for local mode soon.


  • We've resisted adding miniflare specific features that don't have edge equivalents, but this seems like a good exception to make.
  • That said, let's consider this experimental, and not make too much noise about it for now. This will definitely change in the future.
  • We could probably make this work on the edge too. For module workers, we could wrap the worker in a facade that exposes a route that triggers the default.scheduled export. For service workers, we'd have to override addEventListener and wrap the fetch handler with our own thing.

@petebacondarwin petebacondarwin added this to the 2.1 milestone May 4, 2022
@petebacondarwin petebacondarwin added enhancement New feature or request and removed feature labels May 12, 2022
@petebacondarwin petebacondarwin modified the milestones: Selected for development, Backlog May 15, 2022
@petebacondarwin petebacondarwin moved this to Backlog in workers-sdk May 15, 2022
@petebacondarwin petebacondarwin removed this from the Backlog milestone May 15, 2022
@threepointone threepointone moved this from Backlog to Selected for development in workers-sdk Jul 28, 2022
@cameron-robey cameron-robey moved this from Selected for development to In Progress in workers-sdk Aug 5, 2022
@cameron-robey cameron-robey moved this from In Progress to In Review in workers-sdk Aug 23, 2022
@lrapoport-cf lrapoport-cf added the blocked Blocked on other work label Sep 7, 2022
@cameron-robey cameron-robey removed the blocked Blocked on other work label Sep 12, 2022
@cameron-robey cameron-robey moved this from In Review to In Progress in workers-sdk Sep 12, 2022
@cameron-robey cameron-robey removed their assignment Sep 12, 2022
Repository owner moved this from In Progress to Done in workers-sdk Sep 15, 2022
cameron-robey added a commit that referenced this issue Sep 15, 2022
Using the new middleware (#1735), we implement a way of testing scheduled workers from a fetch using `wrangler dev` in remote mode, by passing a new command line flag `--test-scheduled`. This exposes a route `/__scheduled` which will trigger the scheduled event.

```sh
$ npx wrangler dev index.js --test-scheduled

$ curl http://localhost:8787/__scheduled
```

Closes #570
mrbbot added a commit that referenced this issue Oct 31, 2023
Miniflare 3 no longer includes a CLI. We're encouraging people to use
Wrangler instead.

Closes DEVX-627
mrbbot added a commit that referenced this issue Nov 1, 2023
Miniflare 3 no longer includes a CLI. We're encouraging people to use
Wrangler instead.

Closes DEVX-627
mrbbot added a commit that referenced this issue Nov 1, 2023
Miniflare 3 no longer includes a CLI. We're encouraging people to use
Wrangler instead.

Closes DEVX-627
mrbbot added a commit that referenced this issue Nov 1, 2023
Miniflare 3 no longer includes a CLI. We're encouraging people to use
Wrangler instead.

Closes DEVX-627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
6 participants