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

    Ceru ©

    04/17/2021, 1:51 PM
    but i dont know if the state is reset
  • c

    Ceru ©

    04/17/2021, 1:51 PM
    it would make sense for the state to reset as it could lead to corruption and such but ive never got the chance to test it personally
  • d

    Deleted User

    04/17/2021, 2:24 PM
    would it be possible to somehow use a snowflake as id?
  • d

    Deleted User

    04/17/2021, 2:25 PM
    i guess you'd just do an
    idFromName
  • j

    john.spurlock

    04/17/2021, 3:35 PM
    "i believe the DO is reset upon code change" - this is not the case. the underlying storage remains, even if the DO code changes
  • c

    Ceru ©

    04/17/2021, 4:00 PM
    got it, thanks!
  • v

    vans163

    04/17/2021, 5:05 PM
    Copy code
    elixir
    class Ring {
      async fetch(request) {    
        if (!this.initializePromise) {
          this.initializePromise = this.initialize().catch((err) => {
            this.initializePromise = undefined;
            throw err
          });
        }
        await this.initializePromise;
        this.do_tick();
        ...
      }
    
      do_tick() {
        if (this.tickPending)
          return;
        this.tickPending = true;
        setTimeout(tick, 1000);
      }
      async tick() {
        setTimeout(tick, 1000);
      }
    }
    Does this look sane? I want to have a 1 second tick inside my DO, if the DO shutsdown+spinsup, itl start ticking.
  • v

    vans163

    04/17/2021, 6:11 PM
    How do you do a get request into a DO with a custom url?
  • v

    vans163

    04/17/2021, 6:11 PM
    i hardcoded a url and ended up calling another worker lol
  • v

    vans163

    04/17/2021, 6:15 PM
    nm seems i can use "/path" only
  • v

    vans163

    04/17/2021, 6:15 PM
    without https
  • v

    vans163

    04/17/2021, 6:15 PM
    and this causes is to go to the DO instead of to a worker
  • g

    GrygrFlzr

    04/18/2021, 4:40 AM
    is there a way to bulk read a bunch of keys or do I have to do it one by one
  • a

    ai

    04/18/2021, 5:23 AM
    Call
    storage.get
    with an array of strings and it returns a map promise. Any missing values are omitted from the result map. (supports up to 128 keys at a time)
  • g

    GrygrFlzr

    04/18/2021, 12:27 PM
    does DO have a KV-style TTL yet that autodeletes it after a time period?
  • b

    Bienvenu

    04/18/2021, 12:46 PM
    @User I had the same question, and there's nothing listed in the API docs - autodeleting storage elements could have been useful!
  • k

    Kevin W - Itty

    04/18/2021, 2:42 PM
    can i fire multiple fetches against a DO stub in parallel and have them all resolve at once? If so, what, if any part of that enforces order? Same with multiple workers accessing the same DO at the same time with parallel fetches...
  • k

    Kevin W - Itty

    04/18/2021, 2:45 PM
    the DO doesn't really have a URL to speak of, because it can't be accessed directly from the internet, only from a DO stub within a worker/other DO (@cf guys feel free to jump in if I'm speaking out of my @$$), so any url is fine, it's just the bit that the DO fetch will see/parse/do something with
  • k

    Kevin W - Itty

    04/18/2021, 2:46 PM
    so most cases I've seen (and what I do) is use a fake/trash domain, and just parse the path from the DO
  • v

    vans163

    04/18/2021, 3:02 PM
    Yea but when I used a full https url, the request seems to go to my worker, not the DO.
  • v

    vans163

    04/18/2021, 3:02 PM
    switched to only the path portion /path it correctly went to the DO now
  • e

    eidam | SuperSaaS

    04/18/2021, 3:03 PM
    Are you sure about this one? I am in some cases just passing the original request
  • v

    vans163

    04/18/2021, 3:04 PM
    i guess i can check it again, original request works fine. I had a worker on 2.zod.tv, and i called a do like obj = CLASS.idFromName("name"); obj.fetch("https://1.zod.tv/path", params) and the request seemed to go to 1.zod.tv/path which was another worker.
  • v

    vans163

    04/18/2021, 3:05 PM
    this was from inside a DO btw
  • v

    vans163

    04/18/2021, 3:05 PM
    so DO calling DO
  • j

    john.spurlock

    04/18/2021, 4:05 PM
    Only guarantee I've seen re: call ordering is the ordering within a single stub client. i.e. calls from that stub will arrive in order on the DO side (or fail) https://developers.cloudflare.com/workers/runtime-apis/durable-objects#object-stubs
  • k

    Kevin W - Itty

    04/18/2021, 4:10 PM
    but since each request is async, do they just guarantee arrival order (async commands within each fetch round trip may execute at diff times), or does each fetch actually fire AND resolve before the next fetch is allowed to call it?
  • k

    Kevin W - Itty

    04/18/2021, 4:10 PM
    just curious which if any race conditions we'll need to deal w
  • k

    kenton

    04/19/2021, 2:29 PM
    Right, only arrival order is guaranteed. If the event handler awaits some I/O, the next event can be delivered in the meantime.
  • k

    Kevin W - Itty

    04/19/2021, 2:31 PM
    So I guess if we need more, we implement a form of transaction lock inside the DO for fetches to check against?
1...646566...567Latest