Milan
Milan
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
No worries, happy to help 🙂, good luck building!
18 replies
CDCloudflare Developers
Created by Mitya on 10/25/2024 in #durable-objects
Hi everyone, I'm new to durable objects
@Mitya this is also useful as a starting point https://blog.cloudflare.com/introducing-workers-durable-objects/ If you're familiar with Cloudflare Workers, you can think of a Durable Object as a special type of worker. Rather than having your requests be handled by any Worker instance, you can have them handled by a particular Durable Object instance. This is what lets you "serialize" (i.e. order requests into a single file line) and "coordinate" (all requests go to the same place) . Then, you can have a bunch of these individual Durable Object "instances", and can decide where you want to route your requests to. Since you can route any request to a particular "instance", you can have in-memory state shared between requests. This doesn't work for normal workers because you can't guarantee any 2 requests go to the same worker instance (no way to share memory if you're in different data centers 😉). Durable Objects also give you access to private local storage through the storage API. If you have any state that isn't ephemeral, you can just write it to DO storage (KV or SQL api -- note this is not Cloudflare KV, which is another product). Anything successfully written to storage is considered durable (we replicate for fault tolerance), so if the machine crashes or your DO is evicted and loses in-memory state, you can read from storage when the next request comes in and you're back to where you were.
3 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
these are "application-level messages", the websocket protocol supports sending protocol level pings (which are invisible to you if you're programming a browser client for example). That's not particularly useful for most people, which is why we let you define an "application-level ping"
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
If you set new WebSocketRequestResponsePair("foo", "bar"), then have your client (browser, python srcipt, whatever it happens to be) do a ws.send("foo"), easy as that 🙂
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
sorry got bogged down by stuff. This should work
this.ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair("foo", "bar"))
this.ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair("foo", "bar"))
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Brb in like an hour or so
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
IIRC our runtime (workers generally) doesn't do any keep-alive stuff for WS, but other Cloudflare services that sit between your client and your DO do enforce keep-alives, so auto-response is a great way to work around that
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
@lukejacksonn setting the auto-response gets you 50% of the way there. You then want your clients to periodically send a websocket message with the "Request" text you set. The auto-response API basically means: if my DO receives this message, then the system will reply with the pre-defined response without invoking your application logic. Therefore, if your DO is hibernating and it receives a message it would auto-respond to, we will not wake your DO from hibernation.
18 replies
CDCloudflare Developers
Created by egg on 9/24/2024 in #durable-objects
Am I doing something wrong here? I'm
7 replies
CDCloudflare Developers
Created by egg on 9/24/2024 in #durable-objects
Am I doing something wrong here? I'm
The hibernation API's this.ctx.acceptWebSocket() doesn't really work the same way ws.accept() works, so I'm not surprised they aren't experiencing the same behavior. That said, I'm surprised you're saying there's a 2 second delay to close your websocket. Is this observed on the client?
7 replies
CDCloudflare Developers
Created by egg on 9/24/2024 in #durable-objects
Am I doing something wrong here? I'm
Yeah, but you're saying this happens always, in what scenario are you calling reject_websocket()?
7 replies
CDCloudflare Developers
Created by egg on 9/24/2024 in #durable-objects
Am I doing something wrong here? I'm
I'm confused, why is server.accept() always throwing?
7 replies
CDCloudflare Developers
Created by geekergame on 9/21/2024 in #durable-objects
Thread
What do you mean by "no count"
2 replies
CDCloudflare Developers
Created by Kaique Anarkrypto on 9/18/2024 in #durable-objects
Persist DO alive during worker deploy
Sure but you control the "node", right? I understand creating an outgoing WS from a DO to some server you don't control, but it's a bit less obvious to me why that's the best approach when you control both the DO and the other server (if disconnects are intolerable). Rather than having some long running task where your DO could disconnect, it would make more sense if your server just sent an http request to your DO when a new event happened, no?
7 replies
CDCloudflare Developers
Created by Kaique Anarkrypto on 9/18/2024 in #durable-objects
Persist DO alive during worker deploy
That said, maybe if your Worker and your DO are deployed in different scripts it won't be the case that every time you deploy the worker it resets the DO?
7 replies