-
Notifications
You must be signed in to change notification settings - Fork 925
run_worker_first support in wrangler #9509
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
Conversation
🦋 Changeset detectedLatest commit: 79c6ce9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
fa21799
to
d4ca6c7
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
3916678
to
0ec5888
Compare
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.
Various minor comments but looks good!
packages/workers-shared/utils/configuration/parseStaticRouting.ts
Outdated
Show resolved
Hide resolved
packages/workers-shared/utils/configuration/parseStaticRouting.ts
Outdated
Show resolved
Hide resolved
if (assets?.routerConfig?.static_routing) { | ||
const rawAssetConfig = | ||
assets.routerConfig.static_routing.asset_worker?.map( | ||
// unparse this for upload :( |
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 doesn't seem ideal. Why does Wrangler need to split the original array except for local dev?
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.
I agree, this is definitely not ideal :(
I put it here as remote dev and deploy both need it, but on reflection its probably easier to just pass the whole thing through even if its redundant in dev (cec7cc0).
it would be good to disentangle dev asset options and upload asset options entirely, but probably best for a followup PR
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.
Nice work. Just a bunch of nits and queries
fixtures/workers-with-assets-static-routing/public/worker/worker-runs.html
Outdated
Show resolved
Hide resolved
fixtures/workers-with-assets-static-routing/spa-assets/index.html
Outdated
Show resolved
Hide resolved
packages/workers-shared/utils/configuration/parseStaticRouting.ts
Outdated
Show resolved
Hide resolved
import { parseStaticRouting } from "../configuration/parseStaticRouting"; | ||
|
||
describe("parseStaticRouting", () => { | ||
it("throws when given empty rules", () => { |
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.
OOC - why throw an error for some invalid rules but return an object containing {errors}
for other invalid rules?
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.
partially because i'm just copying EWC's validation exactly.
but also the ones that throw are 'general' errors, and the ones that we collect are rule-specific errors.
expect(errorMessage).toMatchInlineSnapshot( | ||
` | ||
"Invalid routes in run_worker_first: | ||
'/api/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': all rules must be less than 100 characters in length" |
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.
Interesting note: the !
of negative rules does not count towards the maximum size, right?
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.
I don't think so, since i don't think we store them with the !
- @matthewdavidrodgers is this right?
if (typeof config.assets?.run_worker_first === "boolean") { | ||
routerConfig.invoke_user_worker_ahead_of_assets = | ||
config.assets.run_worker_first; | ||
} else if (Array.isArray(config.assets?.run_worker_first)) { | ||
const { parsed, errorMessage } = parseStaticRouting( | ||
config.assets.run_worker_first | ||
); | ||
if (errorMessage) { | ||
throw new UserError(errorMessage, { | ||
telemetryMessage: "invalid run_worker_first rules", | ||
}); | ||
} | ||
routerConfig.static_routing = parsed; | ||
} |
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.
Just wondering if it would simplify things in miniflare
, wrangler dev
and vite dev
if parseStaticRouting
received the run_worker_first
value directly and treated true
as an alias for { parsed: { user_worker: ["/*"] }}
? That way we wouldn't need to worry about the invoke_user_worker_ahead_of_assets
value. false
could return { parsed: undefined }
. No big deal if not. This only changes the internals so we could always do this later. cc @petebacondarwin.
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.
It is likely that the internal implementation of run_worker_first: true
is simplified (i.e. no need to do any pattern matching at all), so I am hesitant to say we should alias true
to /*
.
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.
Sure. I'm happy to keep things as they are.
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.
yeah its what pete said - router worker actually getst this as two different config options invoke_user_worker_ahead_of_assets
or static_routing
a73a801
to
957e4a4
Compare
Supersedes #9304
Follows on from #9416