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

    Gavin

    05/07/2021, 8:17 PM
    when using the storage.put method and passing an object with multiple key and values, what should that object look like? i'm doing something like { somekey: somevalue, anotherkey: anothervalue } but it doesn't seem to be working properly. does it need to be { "somekey": somevalue, "anotherkey":anothervalue} or something else?
  • m

    Mallissin

    05/08/2021, 12:13 AM
    Are you JSON.stringify-ing your data being stored?
  • d

    Deleted User

    05/08/2021, 2:29 AM
    isn't the point of DOs that you don't have to do that?
  • d

    Deleted User

    05/08/2021, 2:29 AM
    wdym by it doesn't seem to be working properly?
  • d

    Deleted User

    05/08/2021, 2:30 AM
    await storage.get('somekey')
    isn't working?
  • u

    Unsmart | Tech debt

    05/08/2021, 2:52 AM
    the main point of DO is consistency not json.stringify or not if you can even save it as a value other than a string
  • d

    Deleted User

    05/08/2021, 4:01 AM
    the other main point is in the name - "objects"
  • d

    Deleted User

    05/08/2021, 4:01 AM
  • d

    Deleted User

    05/08/2021, 4:01 AM
    > Each value can be any type supported by the structured clone algorithm, which is true of most types.
  • g

    Gavin

    05/08/2021, 6:00 AM
    As in the data doesn't seem to get stored at all but i think the problem is that line of my code that calls to the DO isn't being executed when deployed but does when using wrangler dev 😭 no idea why but it's breaking the whole thing as values in the DO are leaking now
  • u

    Unsmart | Tech debt

    05/08/2021, 6:42 AM
    Whats the code you are using? and did you try JSON.stringify? maybe they have an issue where its not actually storing object values like it should
  • u

    Unsmart | Tech debt

    05/08/2021, 6:44 AM
    Also I had no idea wrangler dev worked for DO thought it didnt must have added it in somewhat recently and I missed it lol
  • a

    Alex Braunreuther

    05/08/2021, 9:25 AM
    Can a DO be bound somehow to a fetchevent worker? I tried already to build a module based worker, deploy it with new-class and then bind the DO to the fetchevent worker but could not get it working.
  • g

    Greg Brimble | Cloudflare Pages

    05/08/2021, 9:52 AM
    It cannot. You need to use modules to use DO. Hopefully wouldn't be too much work to convert the service worker Worker?
  • a

    Alex Braunreuther

    05/08/2021, 9:53 AM
    Alright thanks! The conversion was no problem, but on the module based worker the request.cf property is empty and I was using the geolocation data. Is this not available anymore?
  • g

    Greg Brimble | Cloudflare Pages

    05/08/2021, 9:55 AM
    Think I've seen someone talking about that before. If the entrypoint Worker's
    request.cf
    is empty, then that's a bug for sure. Not sure if the team have been properly alerted (cc. @User ?). But within the DO fetch handler, I imagine that could be empty, since it's not a real over-the-internet request that it handles.
  • a

    Alex Braunreuther

    05/08/2021, 9:58 AM
    Yup I'm not talking of the request in the DO. It's the request.cf in the default export of the worker which uses the DO. That's why I thought my option would be to switch back to the fetchEvent 😄
  • a

    Alex Braunreuther

    05/08/2021, 9:59 AM
    Didn't do a bug report so far - what would be the channel for this?
  • g

    Greg Brimble | Cloudflare Pages

    05/08/2021, 10:00 AM
    Albert'll hopefully catch this on Monday and pass it on to the team to investigate 🙂
  • j

    jed

    05/08/2021, 10:28 AM
    fwiw: https://discord.com/channels/595317990191398933/773219443911819284/834500066222800906
  • g

    Gavin

    05/08/2021, 11:05 AM
    you have to actually publish the DO, so not great in terms of testing offline but helps when you need some console logs 🙂
  • g

    Gavin

    05/08/2021, 11:07 AM
    is it normal for communication with the DO to sometimes take 30 seconds? one of my calls sometimes does and it's not doing much apart from storing two values
  • v

    vans163

    05/08/2021, 1:32 PM
    I am noticing wierd state bugs where if a DO shuts down or not, it stops processing setTimeout
  • v

    vans163

    05/08/2021, 1:33 PM
    at a certain point a DO stops processing setTimeout even tho its state has not been reset
  • v

    vans163

    05/08/2021, 1:33 PM
    the only fix is to redeploy the DO
  • v

    vans163

    05/08/2021, 1:34 PM
    Copy code
    javascript
    class DOClass {
      do_tick() {
        if (this.tickPending)
          return;
        this.tickPending = true;
        setTimeout(() => this.tick(), 1000)
      }
      async tick() {
        try {
          await this.delegate_jobs();
        } catch (err) {
          this.broadcast(JSON.stringify({opcode: err.message, stack: err.stack}))
        }
        setTimeout(() => this.tick(), 1000)
      }
    }
    code like this
  • v

    vans163

    05/08/2021, 1:34 PM
    where, do_tick is called by every connecting websocket
  • v

    vans163

    05/08/2021, 1:34 PM
    eventually stops ticking
  • v

    vans163

    05/08/2021, 1:34 PM
    but this.tickPending == true, meaning the DO did not shut down
  • v

    vans163

    05/08/2021, 1:35 PM
    (since a shutdown DO would reset its state)
1...808182...567Latest