-
Notifications
You must be signed in to change notification settings - Fork 742
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 multi-worker Durable Object RPC #7098
Conversation
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-wrangler-7098 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7098/npm-package-wrangler-7098 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-wrangler-7098 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-create-cloudflare-7098 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-kv-asset-handler-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-miniflare-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-pages-shared-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-vitest-pool-workers-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workers-editor-shared-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workers-shared-7098 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11521424958/npm-package-cloudflare-workflows-shared-7098 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
const EXTERNAL_SERVICE_RECEIVER_SCRIPT = ` | ||
\n;; ${/* this script needs to be concatenated with the user's script :( -- use this to avoid ASI syntax errors*/ ""} | ||
import { WorkerEntrypoint as __Wrangler__LocalOnly__WorkerEntrypoint } from "cloudflare:workers"; | ||
export class ${EXTERNAL_SERVICE_RECEIVER_NAME} extends __Wrangler__LocalOnly__WorkerEntrypoint { | ||
async proxyMethod({ bindingName, doId, method, args }) { | ||
const ns = this.env[bindingName]; | ||
const stub = ns.get(ns.idFromString(doId)); | ||
return stub[method](...args); | ||
} | ||
} | ||
`; |
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.
This script is added to the user's script – not a separate service as the previous implementation did – so we can bind to it as a regular external entrypoint
This may sound scary but I've taken care to use long+clear names to avoid clashing with user variables in scope and that explain their purpose so if a user ever does discover them they will understand its: (a) injected by wrangler and (b) in local code only, not deployed code
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 could avoid this if we could introduce a concept to the dev registry of an entrypoint within a worker[1] within a worker[2]
[1] miniflare subworker
[2] dev registry worker (user worker)
// redeclare internal durable object bindings for use by __Wrangler__LocalOnly__ExternalDurableObjectsReceiver | ||
...internalObjects.map(({ class_name, script_name }) => { | ||
const useSQLite = classNameToUseSQLite.get(class_name); | ||
const bindingName = getIdentifier( | ||
`__Wrangler__LocalOnly__DurableObject__${class_name}` | ||
); | ||
return [ | ||
bindingName, | ||
{ | ||
className: class_name, | ||
useSQLite, | ||
script_name, | ||
}, | ||
]; | ||
}), |
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.
These bindings are also added to the user's worker and on their env object but, again, I've taken care to make long+clear names for the same reasons as above
@@ -19,6 +19,6 @@ export default defineConfig({ | |||
restoreMocks: true, | |||
// A lot of the fixture tests are extremely flaky because of the dev registry | |||
// Retry tests by default so that only real errors are reported | |||
retry: 2, | |||
retry: 0, |
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.
Is this temporary? If not then perhaps update the comment?
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.
Temporary. Will undo
Closing in favour of #7251 |
Fixes #5918
Support Durable Object RPC across multiple wrangler instances
Only supports RPC method calls right now. RPC property access is coming shortly (in this PR)
The entire implementation is in src/dev/miniflare.ts