-
Notifications
You must be signed in to change notification settings - Fork 259
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
Application-level auto-response for hibernatable web sockets #456
Conversation
eadf6e3
to
74eba04
Compare
ed4234e
to
850c25d
Compare
60e4aef
to
466ddd7
Compare
b6df9f5
to
daad03d
Compare
e310b8f
to
5e0129e
Compare
5e0129e
to
7b73d31
Compare
7b73d31
to
b76993a
Compare
b76993a
to
f4bdadf
Compare
src/workerd/api/actor-state.h
Outdated
JSG_RESOURCE_TYPE(DurableObjectState, CompatibilityFlags::Reader flags) { | ||
JSG_METHOD(waitUntil); | ||
JSG_READONLY_INSTANCE_PROPERTY(id, getId); | ||
JSG_READONLY_INSTANCE_PROPERTY(storage, getStorage); | ||
JSG_METHOD(blockConcurrencyWhile); | ||
JSG_METHOD(acceptWebSocket); | ||
JSG_METHOD(getWebSockets); | ||
JSG_METHOD(setWebSocketAutoresponse); | ||
JSG_METHOD(unsetWebSocketAutoresponse); |
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.
May I suggest using a property getter/setter instead of a pair of methods?
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.
For the getter, do you think it should return a pair<request, response> or should there be two getters, one for request and one for response?
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.
If they always go together, a pair. If they are independent, separate getters/setters
f4bdadf
to
d65f380
Compare
f253264
to
5039bed
Compare
5039bed
to
e4cbde5
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.
Nice cleanup! Glad to see it wasn't too much of a hassle to avoid extending the websocket API
} | ||
|
||
kj::Maybe<jsg::Ref<api::WebSocketRequestResponsePair>> HibernationManagerImpl::getWebSocketAutoResponse() { | ||
KJ_IF_MAYBE(ar, autoResponseRequestResponsePair) { |
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.
nit: this might become a 1 liner if you return autoResponsePair.map(...)
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.
That doesn't seem to work in this case :(
be9989d
to
e610f11
Compare
ab280ae
to
01fc6ff
Compare
9f8b8eb
to
6687ec0
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 Joaquim!
@@ -340,6 +340,28 @@ class ActorState: public jsg::Object { | |||
kj::Maybe<jsg::Ref<DurableObjectStorage>> persistent; | |||
}; | |||
|
|||
class WebSocketRequestResponsePair: public jsg::Object { |
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.
nit: I think this class should have a brief comment describing what it's for:
// A (`RequestMessage`, `ResponseMessage`) pair that's set on a Durable Object for
// Hibernatable WebSocket auto-response. The `RequestMessage` is automatically
// replied to with `ResponseMessage` without forcing the Durable Object to wake from hibernation.
26b1cfb
to
f65bfa0
Compare
Updated and rebased to pass windows tests |
af58280
to
2263ee8
Compare
This commit add a new method for hibernatable web sockets that enables a ping/pong application autoresponse, storing the last received pong timestamp. There's also a method to access the last received timestamp.
2263ee8
to
e9e2fce
Compare
When a specific
request
is set for hiberntabale web socket, they must respond withresponse
, store the timestamp and if currently hibernating, should stay hibernated.This PR adds a new
DurableObjectState::setWebSocketAutoresponse(request: string, response: string);
andWebSocket::getAutoresponseTimestamp();
.