-
Notifications
You must be signed in to change notification settings - Fork 290
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
MQ-498: Add support for delivery delay in Queues #1704
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,20 @@ class WorkerQueue: public jsg::Object { | |
// contentType determines the serialization format of the message. | ||
jsg::Optional<kj::String> contentType; | ||
|
||
JSG_STRUCT(contentType); | ||
JSG_STRUCT_TS_OVERRIDE(QueueSendOptions { | ||
contentType?: QueueContentType; | ||
}); | ||
// The number of seconds to delay the delivery of the message being sent. | ||
jsg::Optional<int> delaySeconds; | ||
|
||
JSG_STRUCT(contentType, delaySeconds); | ||
JSG_STRUCT_TS_OVERRIDE(QueueSendOptions { contentType?: QueueContentType; }); | ||
// NOTE: Any new fields added here should also be added to MessageSendRequest below. | ||
}; | ||
|
||
struct SendBatchOptions { | ||
// The number of seconds to delay the delivery of the message being sent. | ||
jsg::Optional<int> delaySeconds; | ||
|
||
JSG_STRUCT(delaySeconds); | ||
JSG_STRUCT_TS_OVERRIDE(QueueSendBatchOptions { delaySeconds ?: number; }); | ||
// NOTE: Any new fields added here should also be added to MessageSendRequest below. | ||
}; | ||
|
||
|
@@ -45,17 +55,21 @@ class WorkerQueue: public jsg::Object { | |
// contentType determines the serialization format of the message. | ||
jsg::Optional<kj::String> contentType; | ||
|
||
JSG_STRUCT(body, contentType); | ||
// The number of seconds to delay the delivery of the message being sent. | ||
jsg::Optional<int> delaySeconds; | ||
|
||
JSG_STRUCT(body, contentType, delaySeconds); | ||
JSG_STRUCT_TS_OVERRIDE(MessageSendRequest<Body = unknown> { | ||
body: Body; | ||
contentType?: QueueContentType; | ||
contentType?: QueueContentType; | ||
}); | ||
// NOTE: Any new fields added to SendOptions must also be added here. | ||
}; | ||
|
||
kj::Promise<void> send(jsg::Lock& js, jsg::JsValue body, jsg::Optional<SendOptions> options); | ||
|
||
kj::Promise<void> sendBatch(jsg::Lock& js, jsg::Sequence<MessageSendRequest> batch); | ||
kj::Promise<void> sendBatch(jsg::Lock& js, jsg::Sequence<MessageSendRequest> batch, | ||
jsg::Optional<SendBatchOptions> options); | ||
|
||
JSG_RESOURCE_TYPE(WorkerQueue) { | ||
JSG_METHOD(send); | ||
|
@@ -64,7 +78,9 @@ class WorkerQueue: public jsg::Object { | |
JSG_TS_ROOT(); | ||
JSG_TS_OVERRIDE(Queue<Body = unknown> { | ||
send(message: Body, options?: QueueSendOptions): Promise<void>; | ||
sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>; | ||
sendBatch(messages | ||
: Iterable<MessageSendRequest<Body>>, options ?: QueueSendBatchOptions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's going on with the whitespace in here? Have you managed to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no |
||
: Promise<void>; | ||
}); | ||
JSG_TS_DEFINE(type QueueContentType = "text" | "bytes" | "json" | "v8"); | ||
} | ||
|
@@ -288,6 +304,7 @@ class QueueCustomEventImpl final: public WorkerInterface::CustomEvent, public kj | |
#define EW_QUEUE_ISOLATE_TYPES \ | ||
api::WorkerQueue, \ | ||
api::WorkerQueue::SendOptions, \ | ||
api::WorkerQueue::SendBatchOptions, \ | ||
api::WorkerQueue::MessageSendRequest, \ | ||
api::IncomingQueueMessage, \ | ||
api::QueueResponse, \ | ||
|
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.
Since
delaySeconds
is defined as anint
, what happens in a negative value is provided?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.
We agreed on doing that validation on the server side. I had it as a
uint
before and the error that was thrown was not super descriptive and user-friendly, that's why I changed it to anint
.