Skip to content

scheduled not working #27

@pierremonico

Description

@pierremonico

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

  1. Clone https://github.com/cloudflare/python-workers-examples/tree/main/01-hello
  2. Replace the fetch method by the scheduled method above
  3. Start wrangler with uv run pywrangler dev --test-scheduled
  4. 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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions