Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Use serde for metadata #285

Merged
merged 2 commits into from
Jul 1, 2019
Merged

Use serde for metadata #285

merged 2 commits into from
Jul 1, 2019

Conversation

xtuc
Copy link
Member

@xtuc xtuc commented Jul 1, 2019

This change adds proper construction of the worker metadata, previously
it was an error-prone string.

bindings.rs is used to build certain binding type, currently only
wasm_module is supported.

@xtuc xtuc mentioned this pull request Jul 1, 2019
@xtuc xtuc requested a review from cwndrws July 1, 2019 10:15
@cwndrws
Copy link

cwndrws commented Jul 1, 2019

This looks pretty good to me, except could we move this out of the wranglerjs module, as it will be used for all types of workers?

This change adds proper construction of the worker metadata, previously
it was an error-prone string.

`bindings.rs` is used to build certain binding type, currently only
wasm_module is supported.
@xtuc xtuc force-pushed the refactor-use-metadata-struct2 branch from 8ca066e to 3d03916 Compare July 1, 2019 14:30
@xtuc
Copy link
Member Author

xtuc commented Jul 1, 2019

Good point @cwndrws, I moved the metadata and bindings into settings.

let mut metadata_file = File::create(self.metadata_path())?;
metadata_file.write_all(create_metadata(self).as_bytes())?;
metadata_file.write_all(metadata.as_bytes())?;
Copy link

Choose a reason for hiding this comment

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

I know this didn't originate from this PR, but why do we write the metadata to a file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its useful if you want to use wrangler as a "build-only" tool

Copy link

Choose a reason for hiding this comment

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

But metadata isn't used unless you're publishing to Cloudflare, so we support building with wrangler and then publishing with curl or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe as part of a CI process where the CI handles upload because wrangler doesn't support complex config for handling staging environments etc. I think it's useful for all "files" that we upload for multipart to end up on disk somewhere for this reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

does it stay on disk? or is it cleaned up later?

Copy link
Member Author

@xtuc xtuc Jul 1, 2019

Choose a reason for hiding this comment

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

There was some back and forth with the metadata file lately, see #276. The file is store in ./worker as part of the worker "bundle", it is persistent.

I'm sure some people will commit their worker, it make sense to have a consistent state including the metadata, it's useful for the preview and debugging too.

@ashleymichal
Copy link
Contributor

probably not now, but settings is ripe for some extractions.

.to_string()
bindings.push(Binding::new_wasm_module(
bundle.get_wasm_binding(),
bundle.get_wasm_binding(),
Copy link
Contributor

Choose a reason for hiding this comment

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

twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Once is the name and the other the multipart part.

@xtuc
Copy link
Member Author

xtuc commented Jul 1, 2019

@ashleymichal

probably not now, but settings is ripe for some extractions.

I don't feel strong about the directory, feel free to suggest something else.

@ashleymichal
Copy link
Contributor

ashleymichal commented Jul 1, 2019

@ashleymichal

probably not now, but settings is ripe for some extractions.

I don't feel strong about the directory, feel free to suggest something else.

I think it's just fine for now, it's sort of a "needs design" thing that will be relatively painless to refactor after the fact.

}

impl Binding {
pub fn new_wasm_module(name: String, part: String) -> Binding {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems odd; why would we want a wasm-specific method on the binding trait? or am i reading this wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is too add for each binding type a method (like a factory, constructor), see https://github.com/cloudflare/wrangler/pull/215/files#diff-deeb786858380f08f8f4d40680620a9a if it makes more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok that makes sense, thank you.

@xortive
Copy link
Contributor

xortive commented Jul 1, 2019

@ashleymichal

probably not now, but settings is ripe for some extractions.

I don't feel strong about the directory, feel free to suggest something else.

I think bundle deserves its own module, so there is a home within the code for "things that wrangler writes out at the end of a build"

@ashleygwilliams
Copy link
Contributor

let's land . this . after an approving review from @ashleymichal

@xtuc xtuc merged commit f67ab7a into master Jul 1, 2019
@delete-merged-branch delete-merged-branch bot deleted the refactor-use-metadata-struct2 branch July 1, 2019 17:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants