-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I've tried to run a worker on a schedule as described in the docs and in these examples.
Conflicting documentation
The documentation mentions the use of on_scheduled and the handler decorator (same in the changelog).
Both seem outdated, as the only way I found it to get picked up (complains about scheduled function not being available otherwise) is through
from workers import WorkerEntrypoint
class Default(WorkerEntrypoint):
async def scheduled(self, controller, env, ctx):
print("Hello World!")(Using a WorkerEntrypoint in lieu of the handler decorator, and using a scheduled method in lieu of a on_scheduled function)
Actual issue
While this now gets picked up, the scheduled handler documentation claims there is no way to perform local testing by simply using wrangler.toml. You have to pass the --test-schedule flag to wrangler dev.
In my case, this raise a TypeError: Couldn't convert object to Python type, got ScheduledController.
Steps to reproduce
- Clone https://github.com/cloudflare/python-workers-examples/tree/main/01-hello
- Replace the
fetchmethod by thescheduledmethod above - Start wrangler with
uv run pywrangler dev --test-scheduled curl "http://localhost:8787/cdn-cgi/handler/scheduled?cron=*+*+*+*+*"
Closing words
Given the conflicting/incomplete documentation/examples and the difficulty of introspecting pyodide, I might be doing something wrong here; but let's say getting up and running with Python workers in the current state of affairs is not easy. I'd love to use them :)