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

    HardAtWork

    12/20/2022, 4:27 PM
    https://developers.cloudflare.com/workers/platform/limits#number-of-workers
  • h

    HardAtWork

    12/20/2022, 4:27 PM
    Yeah
  • d

    DanTheGoodman

    12/20/2022, 4:27 PM
    I imagine that can be raised?
  • h

    HardAtWork

    12/20/2022, 4:28 PM
    >>> Unless otherwise negotiated as a part of an enterprise level contract, …
  • h

    HardAtWork

    12/20/2022, 4:28 PM
    So yeah
  • d

    DanTheGoodman

    12/20/2022, 4:29 PM
    ah lmao thanks
  • a

    aranchelk

    12/20/2022, 9:29 PM
    Anyone know if it's possible to establish a websocket between two durable objects?
  • g

    geg

    12/20/2022, 9:55 PM
    It is
  • a

    aranchelk

    12/20/2022, 10:01 PM
    How do you create the client side without a URL?
  • h

    HardAtWork

    12/20/2022, 10:02 PM
    You give it a random one. DOs don’t need a specific hostname to work
  • h

    HardAtWork

    12/20/2022, 10:03 PM
    You can call it https://google.com for all it cares
  • a

    aranchelk

    12/20/2022, 10:05 PM
    The client web socket api doesn’t produce a request object, there’s nothing to pass to the fetch method of the stub.
  • h

    HardAtWork

    12/20/2022, 10:07 PM
    https://developers.cloudflare.com/workers/learning/using-websockets/#writing-a-websocket-client
  • h

    HardAtWork

    12/20/2022, 10:07 PM
    When you receive a Response, you can pull a WebSocket out of it
  • a

    aranchelk

    12/20/2022, 10:11 PM
    That’s using a request generated by a browser, I’m asking about establishing a connection between two durable objects.
  • a

    aranchelk

    12/20/2022, 10:16 PM
    It’s either not possible, or maybe there’s an alternate method to initiate sockets in a DO, or there’s a way to extract a remote DO URI from the stub, but I have read the available docs and public code examples and it’s not clear to me how to accomplish this.
  • s

    Skye

    12/20/2022, 10:18 PM
    That example is for the worker side of things
  • a

    aranchelk

    12/20/2022, 10:23 PM
    Unless I’m missing something, that example has a socket request originating in a web client with a DO endpoint. “In client-side JavaScript, connect to your Workers function using WebSockets:”
  • c

    Chaika

    12/20/2022, 10:25 PM
    Look at the "​​Writing a WebSocket client" section?
  • a

    aranchelk

    12/20/2022, 10:28 PM
    Ah, got it, thank you everybody.
  • r

    Rivage

    12/21/2022, 12:59 AM
    Hey guys, have a problem with durable objects appearing as
    undefined
    . Here is my code:
    Copy code
    js
        let id = req.env.rooms.idFromName("index");
        console.log(id)
        console.log(req.env.rooms.get(id))
    which prints the following:
    Copy code
    js
    DurableObjectId {
      name: undefined
    }
    DurableObject {
      name: undefined,
      id: undefined
    }
  • r

    Rivage

    12/21/2022, 1:00 AM
    this is my class:
    Copy code
    js
    export class Chatroom {
        constructor(controller, env) {
            console.log("constructing new object")
            this.storage = controller.storage;
            this.env = env;
            this.sessions = [];
            this.lastTimestamp = 0;
        }
    
        async fetch(req) {
            console.log("fetch")
            if (req.headers.get("Upgrade") !== "websocket") {
                return json("Expected upgrade", 426)
            }
    
            const ws = new WebSocketPair();
            const [client, server] = Object.values(ws);
    
            await this.handleSession(server)
    
            return new Response(null, {
                status: 101,
                webSocket: client
            });
        }
    
        async handleSession(ws) {
            console.log("made it here")
            ws.accept();
    
            ws.addEventListener("message", async msg => {
                ws.send(msg.data)
            })
        }
    }
  • r

    Rivage

    12/21/2022, 1:00 AM
    and my bindings:
    Copy code
    toml
    [durable_objects]
    bindings = [
      { name = "rooms", class_name = "Chatroom" }
    ]
    
    [[migrations]]
    tag = "v1" # Should be unique for each entry
    new_classes = ["Chatroom"]
  • r

    Rivage

    12/21/2022, 1:01 AM
    Would appreciate any pointers!
  • r

    Rivage

    12/21/2022, 1:22 AM
    To be clear, the specific error is:
    Copy code
    js
    /Users/bigballs/rizzle/backend/node_modules/wrangler/wrangler-dist/cli.js:27100
                throw ex;
                ^
    
    Error: read ECONNRESET
        at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
    Emitted 'error' event on Socket instance at:
        at emitErrorNT (node:internal/streams/destroy:151:8)
        at emitErrorCloseNT (node:internal/streams/destroy:116:3)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      errno: -54,
      code: 'ECONNRESET',
      syscall: 'read'
    }
  • a

    aarhus

    12/21/2022, 8:46 AM
    Morning all, I have a requirement that if the DO code is changed, then a job needs to run when the update is pushed. Anyone got any patterns for this?
  • a

    aarhus

    12/21/2022, 8:48 AM
    Are you doing anything after the "console.log(req.env.rooms.get(id))"
  • h

    HardAtWork

    12/21/2022, 9:08 AM
    Have a deployment ID in the DO class that changes automatically on deploy, and then run an alarm every minute(more or less), see if it changed as compared to the stored deployment ID. If so, run the job
  • a

    aarhus

    12/21/2022, 9:25 AM
    Don't I need to do something to set an alarm? i.e. if no request is sent to the DO, then there is no way the alarm can be set.
  • h

    HardAtWork

    12/21/2022, 9:27 AM
    When you initially create it, yes, but after that, the alarm handler can call itself
    a
    • 2
    • 1
1...462463464...567Latest