-
Notifications
You must be signed in to change notification settings - Fork 257
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
Conversation
559cf98
to
d55213b
Compare
Thanks for taking a look, @jasnell ! |
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! 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); | ||
} |
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.
} | |
JSG_TS_OVERRIDE(Message<Body = unknown> { | |
readonly body: Body; | |
}); | |
} |
...and remove:
workerd/types/defines/queues.d.ts
Lines 1 to 25 in 2a71783
/** | |
* 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; | |
} |
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.
Thanks!
|
||
JSG_METHOD(retryAll); | ||
JSG_METHOD(ackAll); | ||
} |
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.
} | |
JSG_TS_OVERRIDE(MessageBatch<Body = unkown> { | |
readonly messages: readonly Message<Body>[]; | |
}); | |
} |
...and remove:
workerd/types/defines/queues.d.ts
Lines 27 to 47 in 2a71783
/** | |
* 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; | |
} |
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 also needed a JSG_TS_ROOT()
and for this file to be included in global-scope.h
, but after that it looks good 👍
|
||
JSG_METHOD(retryAll); | ||
JSG_METHOD(ackAll); | ||
} |
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.
} | |
JSG_TS_OVERRIDE(<Body = unknown> { | |
readonly messages: readonly Message<Body>[]; | |
}); | |
} |
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.
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?
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.
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:
workerd/src/workerd/api/global-scope.h
Lines 92 to 97 in a363226
JSG_TS_DEFINE(type WorkerGlobalScopeEventMap = { | |
fetch: FetchEvent; | |
scheduled: ScheduledEvent; | |
unhandledrejection: PromiseRejectionEvent; | |
rejectionhandled: PromiseRejectionEvent; | |
}); |
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.
Cool, done.
cf2173b
to
71eea19
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.
Thanks for the help with types!
|
||
JSG_METHOD(retryAll); | ||
JSG_METHOD(ackAll); | ||
} |
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.
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); | ||
} |
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.
Thanks!
|
||
JSG_METHOD(retryAll); | ||
JSG_METHOD(ackAll); | ||
} |
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 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.
1d14f58
to
87a27a9
Compare
This required a few more changes than the binding did, so merits at least a slightly closer review. All internal tests pass, at least.