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

    HardAtWork

    03/12/2023, 9:03 AM
    There are three tiers.
    wrangler
    is the CLI,
    miniflare
    is the system that actually mocks a Workers environment, and
    workerd
    , if you choose to use it, is the actual Workers runtime.
  • a

    Advany

    03/12/2023, 9:58 AM
    is there like a framework on top of do that can handle spinning of new do instances when limits are reached? I want to save json objects inside of DO to be quickly available during requests. If I want to store like couple 1000 of json objects inside one DO (one do per client). Would I store everything in one object like this.configs = {} or is there a more efficient way of doing it?
  • f

    frankichiro

    03/12/2023, 10:11 AM
    So… getting DO to work with Pages just needs two CLI flags, but getting DO to work with Workers need an entire workerd installation? That can’t be right… Is there really no tutorial or example available for this? D:
  • h

    HardAtWork

    03/12/2023, 10:14 AM
    No, I was just explaining what the different parts did. To use a DO with Workers, all you need is a
    wrangler.toml
  • j

    johtso

    03/12/2023, 12:38 PM
    "We do plan on improving the lifecycle management of objects soon, and auto-expiration is very likely to be part of that." saw this in a forum post from 2 years ago, did anything happen on this front?
  • h

    HardAtWork

    03/12/2023, 12:39 PM
    Can you link the post in question?
  • j

    johtso

    03/12/2023, 12:39 PM
    https://community.cloudflare.com/t/durable-objects-larger-storage-limit-per-object-time-invalidated-storage/222156/13
  • j

    johtso

    03/12/2023, 12:40 PM
    I guess this was before alarms
  • j

    johtso

    03/12/2023, 12:40 PM
    And now alarms are basically the tool for all lifecycle related things?
  • h

    HardAtWork

    03/12/2023, 12:41 PM
    This is probably the answer, from the thread: > You can build a TTL using alarms. Whenever your object is accessed, you would use
    setAlarm()
    to set the alarm time to
    Date.now() + timeout
    . There is only one alarm per object, so each call to
    setAlarm()
    replaces the previous alarm with the new alarm time. When that time is reached, the alarm handler will be invoked. In your
    alarm
    handler, you would use
    storage.deleteAll()
    to delete your object. > > Since it’s possible to build TTL using alarms, we probably won’t be adding a separate TTL feature. - Kenton
  • j

    johtso

    03/12/2023, 12:45 PM
    Ah well spotted
  • j

    johtso

    03/12/2023, 12:46 PM
    I guess better that energy is put towards stuff that can't be done in user land
  • s

    Subh

    03/12/2023, 6:15 PM
    Can someone help me with this one? Please 🥹
  • l

    Larry

    03/12/2023, 6:28 PM
    I don't think you provided enough details to make a full diagnosis and even if you did, I have no experience with queues and I'm far from knowing all the ins and outs of DO performance. One wild ass guess though... do you use
    env.MY_DO_NAMESPACE.idFromName(name)
    ? Those require a global lookup on object creation and should be avoided.
  • s

    Subh

    03/12/2023, 6:31 PM
    oh ya, that could be it. I am using
    idFromName
    . Changing that to id, that would show significant change I guess?
    l
    c
    • 3
    • 19
  • c

    crabmusket

    03/13/2023, 1:08 AM
    https://github.com/topics/durable-objects I think there should be an awesome-durable-objects repo 😁
  • j

    johtso

    03/13/2023, 1:12 AM
    just found this too https://github.com/ticket-bridge/hyper-durable
  • j

    johtso

    03/13/2023, 1:14 AM
    the extra layer of abstraction it proposes makes my head hurt though
  • f

    frankichiro

    03/13/2023, 11:29 AM
    Hello again. I am still unable to figure out how to do this. It's not very clear in the documentation. :/
  • d

    Deleted User

    03/13/2023, 11:38 AM
    https://miniflare.dev/core/mount#durable-objects Does this help?
  • f

    frankichiro

    03/13/2023, 12:03 PM
    It does not help, unfortunately. Am I supposed to run Miniflare separately from Wrangler?
  • d

    Deleted User

    03/13/2023, 12:26 PM
    https://discord.com/channels/595317990191398933/773219443911819284/1069328319314677830 Found this To be honest I haven't tried using multiple workers myself 😅 Generally I just use miniflare directly but I haven't checked the new wrangler out in so long
  • d

    Deleted User

    03/13/2023, 12:31 PM
    Ah, it's not linking correctly. Here's his message
  • d

    Deleted User

    03/13/2023, 12:32 PM
    It looks like environment property isn't optional judging from that conversation
  • f

    frankichiro

    03/13/2023, 1:01 PM
    Hey, I solved it! I learned that "script_name" in Worker A's DO binding should be the "name" in Worker B's wrangler.toml-file. So I removed the Miniflare stuff, and made sure the names matched, which required a change from "session" to "sessions", and now it works, finally!
  • f

    frankichiro

    03/13/2023, 1:02 PM
    No environment property needed.
  • f

    frankichiro

    03/13/2023, 1:03 PM
    And of course the two workers must be up and running simultaneously, locally.
  • f

    frankichiro

    03/13/2023, 1:08 PM
    I'd like to say that the documentation on "script_name" is very bad, and it would be nice if someone could update the Durable Objects section to explain this better, giving the above solution for how to do a local binding to another / multiple workers.
  • f

    frankichiro

    03/13/2023, 1:09 PM
    Thanks for your help!
  • t

    themetanull

    03/13/2023, 4:00 PM
    Is there a way to force a Durable object instance to live on a specific colo?
1...517518519...567Latest