Skip to content
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

File based dev registry #5214

Merged
merged 9 commits into from
Jun 19, 2024
Merged

File based dev registry #5214

merged 9 commits into from
Jun 19, 2024

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Mar 8, 2024

What this PR solves / how to test

Fixes #6037

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because: unskipped existing tests
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
Copy link

changeset-bot bot commented Mar 8, 2024

🦋 Changeset detected

Latest commit: 8d92959

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers Patch

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

Copy link
Contributor

github-actions bot commented Mar 8, 2024

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/9585443653/npm-package-wrangler-5214

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5214/npm-package-wrangler-5214

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-wrangler-5214 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-create-cloudflare-5214 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-cloudflare-kv-asset-handler-5214
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-miniflare-5214
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-cloudflare-pages-shared-5214
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9585443653/npm-package-cloudflare-vitest-pool-workers-5214

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.61.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240610.1
workerd 1.20240610.1 1.20240610.1
workerd --version 1.20240610.1 2024-06-10

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@penalosa
Copy link
Contributor Author

penalosa commented Mar 11, 2024

  • Add file heartbeat to detect crashed workers
  • Add Wrangler version to files to detect back compat
  • Add cleanup mechanism when Wrangler tries to fetch a worker that no longer exists
@penalosa penalosa force-pushed the penalosa/file-based-dev-registry branch from dd3e0ce to d9913f5 Compare June 17, 2024 17:59
@penalosa penalosa marked this pull request as ready for review June 17, 2024 22:33
@penalosa penalosa requested review from a team as code owners June 17, 2024 22:33
Comment on lines +299 to +300
.option("experimental-registry", {
alias: ["x-registry"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Comment on lines 10 to 16
export const run = <V>(flagValues: ExperimentalFlags, cb: () => V) =>
flags.run(flagValues, cb);

export const FILE_BASED_REGISTRY = () => flags.getStore()?.FILE_BASED_REGISTRY;

// TODO: actually use this
export const DEV_ENV = () => flags.getStore()?.DEV_ENV;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we discuss alternatives to this interface please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely—what are your concerns?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point about interface:

I'd like to make adding a feature flag as easy as adding it to a type with no repetition. Having an exported function per flag requires multiple changes to this file to add each flag. While this allows us to find all usages of each feature flag with Find All References, they won't be easy to find usages of any flag. Can we try something like export const XFLAG = <F extends keyof ExperimentalFlags>(flag: F) => ExperimentalFlags[F];?

More for discussion:

This is a great use of AsyncLocalStorage. Can we generalise this use for other singletons like Logger etc? Are there any parts of wrangler this wouldn't work for?

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't have time to review it. But I see that @RamIdeas has approved.

@@ -27,8 +27,7 @@ describe("'wrangler dev' correctly renders pages", () => {
expect((content as Record<string, object>).run).toEqual("function");
});

// TODO: unskip when https://github.com/cloudflare/workerd/pull/2095 is merged and released
it.skip("ai binding properties", async ({ expect }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

});
await setTimeout(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the need for these pauses? If this is a shortcoming in the file-based reg approach, perhaps it is not ideal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. This is a limitation to how unstable_dev works right now, not related to this refactor.
The problem is that unstable_dev will only read the dev-registry once, rather than polling it for changes.
So we need to make sure that upstream workers are in-place and ready before starting downstream workers.
The wrangler dev command does do polling, so does not have this problem. So normal users would not need such pauses.

Going forward we should add polling or watching to the unstable_dev stuff so that these are no longer needed.

@penalosa penalosa merged commit 05c5607 into main Jun 19, 2024
19 checks passed
@penalosa penalosa deleted the penalosa/file-based-dev-registry branch June 19, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants