https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • j

    john.spurlock

    08/12/2021, 5:10 PM
    Sounds like a fantastic intern project
  • d

    davidbarratt

    08/12/2021, 5:54 PM
    uhh, this is probably a dumb question... but do Durable Objects have to be serializable? or could they contain something like an RxJS Observable that you can push to between incoming requests?
  • d

    davidbarratt

    08/12/2021, 5:55 PM
    basically I want to receive "purge" requests from an Amazon SNS and group the tags together and send a request to Cloudflare's API whenever I get up to 30 or every 3 seconds (whichever comes sooner) so that way we are not spamming their API. ๐Ÿ™‚
  • j

    john.spurlock

    08/12/2021, 6:00 PM
    they do not need to use
    state.storage
    at all if that's what you're asking, can do stuff only in memory. The classic websocket chat server for example can be done without storage if necessary. DOs can be just a nice centralized coordination point
  • d

    davidbarratt

    08/12/2021, 6:00 PM
    interesting, and can you use
    setTimeout()
    within a worker?
  • d

    davidbarratt

    08/12/2021, 6:01 PM
    errr
  • d

    davidbarratt

    08/12/2021, 6:01 PM
    within the Durable Object
  • j

    john.spurlock

    08/12/2021, 6:01 PM
    yep
  • d

    davidbarratt

    08/12/2021, 6:01 PM
    nice!
  • d

    davidbarratt

    08/12/2021, 6:04 PM
    I think this is going to make my life a lot easier. ๐Ÿ™‚
  • d

    davidbarratt

    08/12/2021, 6:06 PM
    another question... is it possible to force a specific location rather than just wherever it is hit first?
  • j

    john.spurlock

    08/12/2021, 6:09 PM
    a specific colo? no - they are kind of like normal workers in that respect. but once they are instantiated (i believe they try to do the first instantiation close to the normal worker that spawned it), they pretty much stay put
  • d

    davidbarratt

    08/12/2021, 6:12 PM
    right, I'm trying to reduce the latency from our AWS region (Ashburn, VA) and I was wondering if I could force it in that colo rather than wherever someone else hits it
  • j

    john.spurlock

    08/12/2021, 6:14 PM
    you could vpn to north va or hit it first from ec2 or lambda or something inside us-east-1
  • j

    john.spurlock

    08/12/2021, 6:14 PM
    but there's no guarantee
  • d

    davidbarratt

    08/12/2021, 6:14 PM
    right
  • j

    john.spurlock

    08/12/2021, 6:14 PM
    could always check the colo once created and keep trying, using a different id or idFromName in the stub call
  • j

    john.spurlock

    08/12/2021, 6:16 PM
    but none of this behavior is guaranteed (they might be doing a server migration e.g.) and might change in the future etc
  • d

    davidbarratt

    08/12/2021, 6:17 PM
    interesting ok, I guess that is a feature request for the workers team... kind of like "get me as close to X location as you can" kind of thing
  • j

    john.spurlock

    08/12/2021, 6:20 PM
    i would love this as well - right now you can specify the "eu jurisdictional area" but that's the only supported physical constraint you can set
  • d

    davidbarratt

    08/12/2021, 6:25 PM
    Is the Durable Object smart enough to know the setTimeout is still running or do you have to put that in the waitUntil ?
  • j

    john.spurlock

    08/12/2021, 6:27 PM
    i believe it's smart enough, iirc they said recently waitUntil has no benefit in DO workers - I've used setTimeout outside of waitUntil and it seems to work - maybe one of the cloudflare folks can confirm this is still the case - things change quickly in DO land : )
  • j

    john.spurlock

    08/12/2021, 6:28 PM
    lots of good stuff in the scrollback for this channel
  • b

    brett

    08/12/2021, 6:33 PM
    You don't need to use a waitUntil in a DO. As far as location, John is right that the object will be created near the first requestor. If your IDs are known in advance you could create them all from us-east. In the future DOs will move (to optimize for latency, or other goals), but for the short term I would consider them stationary.
  • d

    davidbarratt

    08/12/2021, 6:34 PM
    well this is all great news because I think I can do what I want in a Worker without having to make/deploy a Node.js service. ๐Ÿ™‚
  • g

    Greg-McKeon

    08/12/2021, 7:55 PM
    just to clarify - the setTimeout might not complete if there's a crash or your DO runs out of execution time. Once the DO is evicted from memory, the setTimeout won't be called. We're working on adding an API that guarantees that the setTimeout will run, even in the event of eviction/failure.
  • b

    brett

    08/12/2021, 8:14 PM
    ๐Ÿ‘‰ ๐Ÿค• ๐Ÿ‘ˆ computers don't fail, Greg
  • i

    ItsWendell

    08/12/2021, 9:38 PM
    The DO storage is generally based on input order right?
  • i

    ItsWendell

    08/12/2021, 9:47 PM
    Any tips regarding this? I implemented some sort of chat history in https://edgechat-graphql.vercel.app which basically writes the chat messages in the DO 'storage' before emitting to the chatroom, but the output once I actually fetch the messages is this
  • i

    ItsWendell

    08/12/2021, 9:47 PM
1...148149150...567Latest