-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Python workers: Replace remaining examples with on_fetch with WorkerEntrypoint class #25794
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
Changes from all commits
52519e7
d0fb0a7
b7b4a68
30a3d8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,14 +71,17 @@ Create (trigger) a new instance of a given Workflow. | |
| type. | ||
|
|
||
| ```python | ||
| from pyodide.ffi import to_js | ||
| from js import Object | ||
| from pyodide.ffi import to_js | ||
| from workers import WorkerEntrypoint, Response | ||
|
|
||
|
|
||
| async def on_fetch(request, env, ctx): | ||
| event = {"foo": "bar"} | ||
| options = to_js({"params": event}, dict_converter=Object.fromEntries) | ||
| await env.MY_WORKFLOW.create(options) | ||
| return Response.json({"status": "success"}) | ||
| class Default(WorkerEntrypoint): | ||
| async def fetch(self, request): | ||
| event = {"foo": "bar"} | ||
| options = to_js({"params": event}, dict_converter=Object.fromEntries) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this is correct at the moment. But since we recently started wrapping the binding in the workers module, we can do this internally (with a compat flag)?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it would be good to do that, we plan to do this for all bindings eventually |
||
| await self.env.MY_WORKFLOW.create(options) | ||
| return Response.json({"status": "success"}) | ||
| ``` | ||
|
|
||
| :::note | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to import
WorkerEntrypointas well