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

    brett

    02/09/2023, 10:15 PM
    DOs only operate on IDs, the same name at a different time generates the exact same ID (
    idFromName("kody") == 1234foobar
    forever)
  • b

    brett

    02/09/2023, 10:26 PM
    > wait for it to die, and then try spawning it again, it will still spawn in the same place To actually answer your question though, yes. But also this is an implementation detail subject to change. We may delete objects (that have no data) at any time, and also eventually we'll relocate objects whether they have data or not
  • s

    Skye

    02/09/2023, 10:30 PM
    I would personally like a Delete DO method
  • s

    Skye

    02/09/2023, 10:31 PM
    Useful for if I have a DO associated with a user (which i get from idFromName) and the user decides to delete their profile - if someone makes an account with the same username, they may have a DO that previously was for someone else on the other side of the world
  • w

    weide

    02/09/2023, 10:39 PM
    i have similar question for DO delete/cleanup. by looking at the chatroom example, if the chat room is no longer used or no need to exist, how can i delete do from the storage.
  • b

    brett

    02/09/2023, 10:41 PM
    If you call
    deleteAll()
    within an object and it succeeds, there's no storage left to bill for
  • b

    brett

    02/09/2023, 10:41 PM
    Yeah, the pinned location is a problem we intend to solve for sure
  • j

    johtso

    02/10/2023, 12:04 AM
    Probably a good idea to not use a username as a primary key, and instead to generate a random primary key and associate the username with that
  • u

    Unsmart | Tech debt

    02/10/2023, 12:05 AM
    aws cognito moment
  • j

    johtso

    02/10/2023, 12:10 AM
    also means a user can change their username without all references breaking
  • f

    frankichiro

    02/10/2023, 6:53 AM
    Hello! How do I interact with a Durable Object locally when developing for Pages? The documentation is mysteriously missing this specific section...
  • h

    HardAtWork

    02/10/2023, 6:53 AM
    Guess I was under the mistaken impression that the location of the DO is encoded into the ID
  • z

    zehawk

    02/10/2023, 8:40 AM
    That would be swell. It goes with the ethos of Cloudflare of shielding needless infra management fiddling from devs.
  • f

    frankichiro

    02/10/2023, 9:22 AM
    Ok, I've found the "--do NAME=CLASS" option for
    wrangler pages dev
    but I don't understand how to use it. I get "DurableObjectError [ERR_CLASS_NOT_FOUND]". How do I link the class?
  • h

    HardAtWork

    02/10/2023, 9:25 AM
    You have to run a separate
    wrangler dev
    session with a Worker that exposes
    CLASS
  • f

    frankichiro

    02/10/2023, 9:25 AM
    Aaaahhh, I see
  • f

    frankichiro

    02/10/2023, 9:25 AM
    Ok, I'll try that. Thanks!
  • f

    frankichiro

    02/10/2023, 9:42 AM
    Nope, didn't work. I am confused about the setup for this... I have an empty worker, because I use a DO binding in my Pages settings, not a Service binding. And when I run
    wrangler dev
    for my Page locally, I add
    --do SESSION=Session
    , and have the DO Worker running at the same time, but I still get 'Class "Session" for Durable Object "SESSION" not found'. What am I missing?
  • d

    Dani Foldi

    02/10/2023, 10:01 AM
    Hi, we seem to be hitting an issue with ws connections in DOs, where if the DO runs out of CPU time, but the ws isn't closed within the script, the runtime doesn't close/notify the client either, so we end up with ghost websockets that can only be cleared by redeploying the worker (or by closing it from client-side, but we can't do that in this case).
  • s

    sathoro

    02/10/2023, 11:21 AM
    I'm thinking about having an "APIUser" durable object where each of our users would have one such instance. it would store the user id, a list of their api keys, their monthly API usage, etc. then each request would authorize against the list of API keys, check their usage, etc. does that seem like a good use case?
  • u

    0xcaff

    02/10/2023, 5:23 PM
    this problem has become kinda critical to our project. we've opened ticket #2702119 13 hrs ago and haven't gotten a response yet. anyone here know how to escalate? pls send help 🙏
  • s

    sathoro

    02/10/2023, 5:33 PM
    is there a recommended method for figuring out if a durable object already exists in the constructor or do you just have to read a value from storage to check?
  • h

    HardAtWork

    02/10/2023, 6:12 PM
    Second option.
  • s

    sathoro

    02/10/2023, 6:27 PM
    oof just ran into something tricky do not do this, counter will always equal 0
    Copy code
    js
    let { counter = 0 } = await this.state.storage.get(['counter']);
  • s

    sathoro

    02/10/2023, 6:27 PM
    have to convert the Map first...
  • s

    sathoro

    02/10/2023, 6:28 PM
    Copy code
    js
    let { counter = 0 } = Object.fromEntries(await this.state.storage.get(['counter']));
  • s

    sathoro

    02/10/2023, 6:34 PM
    I feel like the whole fetch API with durable objects is pretty bulky. you already have to deal with requests and response in workers, it feels weird having another layer of it. I'd like to be able to put normal methods on the objects
  • z

    zegevlier

    02/10/2023, 6:41 PM
    There are libraries, like
    itty-durable
    , that do that.
  • h

    HardAtWork

    02/10/2023, 7:07 PM
    Couldn't you just do
    Copy code
    js
    let [ counter = 0 ] = await this.state.storage.get(["counter"]);
    , or if you only ever need one value,
    Copy code
    js
    letcounter = await this.state.storage.get("counter") || 0;
    ?
  • s

    sathoro

    02/10/2023, 7:08 PM
    it was a simplified example of course, I was fetching 8 values oh didn't know about that first syntax, that actually works?
1...495496497...567Latest