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

Adding PipelineTransform class #2553

Merged
merged 2 commits into from
Aug 26, 2024
Merged

Conversation

hhoughgg
Copy link
Contributor

This PR adds a class called PipelineTransform which allows us to test PipelineTransform implementations before sending them real data from "Cloudflare Pipelines".

It also means that you don't have to deal with streams directly and can just work with JSON/Javascript Objects.

@hhoughgg hhoughgg requested review from a team as code owners August 19, 2024 17:14
Copy link

github-actions bot commented Aug 19, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hhoughgg
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Aug 19, 2024
src/cloudflare/internal/pipeline-transform.ts Outdated Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Outdated Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Outdated Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Outdated Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Show resolved Hide resolved
@hhoughgg hhoughgg force-pushed the hhoughgg/superpipe branch 8 times, most recently from 3388c5f to 60da101 Compare August 23, 2024 20:28
Copy link
Member

@a-robinson a-robinson left a comment

Choose a reason for hiding this comment

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

Mostly looks good! Just a few small things.

obj.dispatcher = 'was here!';
}

return batch;
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but it'd be nice to test the async nature of this as well -- e.g. modifying each obj a little more after waiting on a scheduler.yield() or something like that.

src/cloudflare/internal/pipeline-transform.ts Outdated Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Show resolved Hide resolved
src/cloudflare/internal/pipeline-transform.ts Show resolved Hide resolved
}

#sendJson(data: object[]): JsonStream {
if (!(data instanceof Array)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd imagine an argument could be made for optionally supporting null and/or undefined instead of an empty array, but that's entirely a product question for you / the team, and it is indeed easier to start strict and loosen this later than the opposite.

const readable = new ReadableStream<Uint8Array>({
start(controller): void {
for (const obj of data) {
const encoded = encoder.encode(`${JSON.stringify(obj)}\n`);
Copy link
Member

Choose a reason for hiding this comment

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

In terms of validating the response from the customer's code, it's also possible for them to return values that will throw when passed to JSON.stringify, and we'd probably benefit from handling them more gracefully than just an uncaught exception?

Although then again in the instanceof Array check above all we do is throw an exception, so actually maybe this is already fine and we just need the calling code to detect this case correctly?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#exceptions

@a-robinson a-robinson merged commit c4ede54 into cloudflare:main Aug 26, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants