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

    Murray

    06/14/2021, 12:03 PM
    #1 create a virtual bucket for each 1 min interval in a day e.g 1 DO or KV namespace with keys like 00:01am, 00:02am etc. To schedule an event for a user, place them in a bucket. To support multiple users/jobs in a 1min bucket the key should be 00:01am_userID. Then schedule a cron job every 1min, using the scheduled time from the event list all jobs/users in the bucket between range (>=) 00:01am_a and 00:02am_z (<=) etc. Call a worker for each. #2. I have same issue. I read in the worker release notes, the sub-request limit is now topped up every request, but think the corn job will still be limited to 50 users in a bucket. 😦
  • j

    jed

    06/14/2021, 12:37 PM
    yeah, i think i'll end up doing something similar: 1. when a user creates a reminder, save the schedule rule and their time zone in their account DO 2. calculate the next event in the schedule, convert it from their timezone to UTC, and use
    new Date().toISOString().slice(0, 16)
    to create a DO stub from something like
    2021-06-14T00:00
    , invoke the DO using
    idFromName
    , and persist a reference to the original schedule. 3. run a
    * * * * *
    cron that uses the same logic to generate the current time string, fetch the DO, iterate over storage executing each rule, pinging the account DO to write the next event a la step 1. 4. run
    deleteAll()
    on the cron DO to clean it up.
  • v

    vodyl

    06/15/2021, 8:57 AM
    Got few questions: 1. I am getting +200ms when I fetch durable object. I know that it's documented that it's in beta and "Not all Cloudflare locations support Durable Objects yet". How can I get an information about where durable object executes? 2. Is there any way to convert form id back to name?
  • v

    vodyl

    06/15/2021, 9:16 AM
    Are there any documented example for this? It should as there is a perception that DD runtime behaves same way as worker so lives only within event scope. For example this case: https://developers.cloudflare.com/workers/learning/using-durable-objects#accessing-persistent-storage-from-a-durable-object removing
    await
    from storagePromise should make no difference if all promises are "automatically waitUntil'd".
  • j

    jed

    06/15/2021, 11:32 AM
    you can check https://where.durableobjects.live/ to see where a DO is created for your PoP.
  • b

    brett

    06/15/2021, 11:56 AM
    It still matters for ordering, though. If you
    await
    , then getting the response (generated after the write
    await
    ) guarantees the write completed. If you didn't
    await
    , the write could fail or the machine the DO is on could crash and not complete the write, and you'd never know. But you're correct that it is otherwise equivalent. I'll see about the docs.
  • b

    brett

    06/15/2021, 12:00 PM
    1. Is this the first request to a given Durable Object? Have you tested subsequent requests? It sounds like you're using named objects, which have to be relocated when they are created. Subsequent requests from the same location are faster. 2. There isn't a way to convert from ID back to name. What you'd probably want to do is store the name itself in the object.
  • v

    vodyl

    06/15/2021, 12:20 PM
    1. where.durable is very useful showing that my Auckland (AKL) transferred to Hong Kong (HKG). So it looks like this is a case. 2. Yes, for me name needs to be available within DD and was looking for a way to extract it from id instead of passing within a request to DD.
  • v

    vodyl

    06/15/2021, 12:38 PM
    Is it possible to implement such a promise retry on a platform level? If it will fail due to an any form of machine crash, platform can make a new activation and then retry/continue from this promise. I think this kind of feature exists in Azure Durable Functions/Orleans. The way how it works is every promise saves it's parameters and result in a DD state and in case of crash, reactivation happens and then platform replays a flow skipping completed one.
  • b

    brett

    06/15/2021, 12:51 PM
    Sure, anything is possible. We should have some things to help here soon. For now just ensuring the promise you create has its own retry will cover a lot of cases (just not crash)
  • v

    Vanessa🦩

    06/15/2021, 5:23 PM
    Wait, that's the first time I hear that. Every storage put should retry in case of failure? How often?
  • b

    brett

    06/15/2021, 5:35 PM
    Well, like anything else on the network a request could fail. It's up to your application whether a retry is safe and necessary. We aim for 0 errors, of course, but you can't depend on that. Mostly I wanted to point out that returning to the user before you're awaited a write means you might be telling the user you did something when you really didn't. šŸ™‚
  • b

    brett

    06/15/2021, 5:36 PM
    But whether that matters is application specific
  • v

    Vanessa🦩

    06/15/2021, 5:37 PM
    How likely is it that a retry will succeed? What are the failure modes? How would I distinguish transient failures from permanent ones?
  • b

    brett

    06/15/2021, 5:40 PM
    I'm not sure how I'd describe an outage in theory... for what its worth, this kind of thing would report an error to us and I can't even think of an instance when it has happened. But the point is that things can, of course, fail.
  • v

    Vanessa🦩

    06/15/2021, 5:45 PM
    Makes sense – anything can fail, yes. In this case (and others we've discussed before) it would be nice to be able to terminate this DO instance - if my app gets into an unrecoverable state I want it to disconnect all websockets (as cleanly as possible) and then "crash", meaning when the client attempts to reconnect it will go to a fresh instance.
  • b

    brett

    06/15/2021, 5:46 PM
    Sure, for what it's worth is the storage layer were that badly broken (most likely because of a terrible network partition, I would guess) the metal/colo itself would eventually evict the actors and they'd fail over to an operational colo
  • v

    Vanessa🦩

    06/15/2021, 5:47 PM
    I mean terminate from, within the worker itself
  • b

    brett

    06/15/2021, 5:47 PM
    But at the limit you can could imagine a user landing in a DO, then the network issue starts 1ms later, and writes fail -- you wouldn't want to respond the user saying "we stored your important transaction" without waiting on the write (if your app has important txns, if not, then you can say whatever you want :P)
  • c

    carlson

    06/16/2021, 12:36 AM
    Need help, I was trying to use Durable Objects on production env (I know the risk), however, the DO is missing on env context but my KV bindings are present. Everything is fine in dev (wrangler publish) but on production (wrangler publish --env production) got
    Cannot read property 'idFromName' of undefined
    . I'm using https://github.com/cloudflare/durable-objects-rollup-esm as a template.
  • c

    carlson

    06/16/2021, 8:30 AM
    I did some back read. I found out the it will be possible to add another durable object per env
    Copy code
    [env.production.durable_objects]
    bindings = [{ name = "INCIDENT", class_name = "Incident" }]
  • c

    carlson

    06/16/2021, 8:32 AM
    Thanks @User
  • e

    eidam | SuperSaaS

    06/16/2021, 8:33 AM
    it is already possible, and no worries!
  • r

    Reaver

    06/16/2021, 2:20 PM
    has anyone got an example of durable objects with websockets? I'm wondering how hard it would be to implement it for Apollo Subscriptions.
  • g

    Greylock

    06/16/2021, 6:43 PM
    For durable objects what’s the best way to represent large lists or collections?
  • g

    Greylock

    06/16/2021, 6:43 PM
    For example in my use, each user has a bunch of transactions that in themselves are small, but there are many of them
  • g

    Greylock

    06/16/2021, 6:43 PM
    I don’t need these to be distributed so it’s fine as one durable object but there’s such a small limit on each value (30kb)
  • g

    Greylock

    06/16/2021, 6:44 PM
    So I can’t just store the array as a value like I hoped
  • v

    vodyl

    06/16/2021, 8:02 PM
    How do you want to query this transactions? Only full dataset, individualy or maybe with period filter?
  • k

    kristian

    06/16/2021, 8:45 PM
    https://twitter.com/CloudflareDev/status/1405265210491871240
1...100101102...567Latest