Cron trigger and executing another Worker

While testing, I created two workers, A and B. A was bound to B and could call it like so:

let heroRequest = await env.randomsuperhero.fetch(request.clone());

However, my intent was for A to be a cron trigger. When I switched it to a scheduled event, request is no longer sent, and now I can’t call my other worker. Is there another way to do this?

You will have to make your own request using new Request(<request body>) to pass to fetch

1 Like

So, something like so?

let heroRequest = await env.randomsuperhero.fetch(new Request('http://127.0.0.1'));

Testing now - I changed my cron to every 5 minutes to see the result quicker. I really wish the dashboard had a ‘run now’ method.

Woot! That worked. I had tried that and it failed before I posted and it failed - but I think I tested wrong. You posting the same solution made me try it again. I do think Cloudflare could possibly add either a utility method (fakeRequest) or somesuch, along with adding a way to test via dashboard, but it’s working. Thank you!!

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