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

Move implementation of queue event handler into workerd #543

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

a-robinson
Copy link
Member

This required a few more changes than the binding did, so merits at least a slightly closer review. All internal tests pass, at least.

src/workerd/api/queue.h Outdated Show resolved Hide resolved
src/workerd/api/queue.h Outdated Show resolved Hide resolved
src/workerd/api/queue.h Outdated Show resolved Hide resolved
@a-robinson
Copy link
Member Author

Thanks for taking a look, @jasnell !

Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

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

Nice! Thanks again for picking this up! 😃 Left some comments about types that can now be auto-generated. 👍

JSG_READONLY_INSTANCE_PROPERTY(body, getBody);
JSG_METHOD(retry);
JSG_METHOD(ack);
}
Copy link
Contributor

@mrbbot mrbbot Apr 17, 2023

Choose a reason for hiding this comment

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

Suggested change
}
JSG_TS_OVERRIDE(Message<Body = unknown> {
readonly body: Body;
});
}

...and remove:

/**
* A message that is sent to a consumer Worker.
*/
interface Message<Body = unknown> {
/**
* A unique, system-generated ID for the message.
*/
readonly id: string;
/**
* A timestamp when the message was sent.
*/
readonly timestamp: Date;
/**
* The body of the message.
*/
readonly body: Body;
/**
* Marks message to be retried.
*/
retry(): void;
/**
* Marks message acknowledged.
*/
ack(): void;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!


JSG_METHOD(retryAll);
JSG_METHOD(ackAll);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}
JSG_TS_OVERRIDE(MessageBatch<Body = unkown> {
readonly messages: readonly Message<Body>[];
});
}

...and remove:

/**
* A batch of messages that are sent to a consumer Worker.
*/
interface MessageBatch<Body = unknown> {
/**
* The name of the Queue that belongs to this batch.
*/
readonly queue: string;
/**
* An array of messages in the batch. Ordering of messages is not guaranteed.
*/
readonly messages: readonly Message<Body>[];
/**
* Marks every message to be retried in the next batch.
*/
retryAll(): void;
/**
* Marks every message acknowledged in the batch.
*/
ackAll(): void;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This also needed a JSG_TS_ROOT() and for this file to be included in global-scope.h, but after that it looks good 👍

src/workerd/api/queue.h Show resolved Hide resolved

JSG_METHOD(retryAll);
JSG_METHOD(ackAll);
}
Copy link
Contributor

@mrbbot mrbbot Apr 17, 2023

Choose a reason for hiding this comment

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

Suggested change
}
JSG_TS_OVERRIDE(<Body = unknown> {
readonly messages: readonly Message<Body>[];
});
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it intentional that you're not specifying a name here?

It looks like before this code move, we were just defining one type (MessageBatch that effectively both QueueEvent and QueueController implemented. Is there a need to export this type at all given how we're renaming QueueController's type below?

FWIW this is currently being ignored due to the lack of a JSG_TS_ROOT(), and that seems ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

Given this inherits ExtendableEvent, I suspect we do want a separate type, like we do with ScheduledEvent/ScheduledController. The renaming of QueueController was to match the existing type and avoid a breaking change. I also think we'll need to add an entry for QueueEvent here:

JSG_TS_DEFINE(type WorkerGlobalScopeEventMap = {
fetch: FetchEvent;
scheduled: ScheduledEvent;
unhandledrejection: PromiseRejectionEvent;
rejectionhandled: PromiseRejectionEvent;
});

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, done.

Copy link
Member Author

@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.

Thanks for the help with types!

src/workerd/api/queue.h Show resolved Hide resolved

JSG_METHOD(retryAll);
JSG_METHOD(ackAll);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Is it intentional that you're not specifying a name here?

It looks like before this code move, we were just defining one type (MessageBatch that effectively both QueueEvent and QueueController implemented. Is there a need to export this type at all given how we're renaming QueueController's type below?

FWIW this is currently being ignored due to the lack of a JSG_TS_ROOT(), and that seems ok?

JSG_READONLY_INSTANCE_PROPERTY(body, getBody);
JSG_METHOD(retry);
JSG_METHOD(ack);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!


JSG_METHOD(retryAll);
JSG_METHOD(ackAll);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This also needed a JSG_TS_ROOT() and for this file to be included in global-scope.h, but after that it looks good 👍

This required a few more changes than the binding did, so merits at
least a slightly closer review. All internal tests pass, at least.
@a-robinson
Copy link
Member Author

@mrbbot or @jasnell is either of you up for approving this? Josh's doesn't count since he isn't a maintainer.

@a-robinson a-robinson merged commit 7c8fe9d into main Apr 19, 2023
6 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.

None yet

4 participants