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

    p0

    01/01/2023, 5:06 AM
    which means it's going to be more expensive than just using cloudflare DO
  • s

    sks

    01/01/2023, 5:09 AM
    Yes, in a way, but what I am saying is, you can consider this an option if you're wanting simpler implementation and not worry about dynamic pricing. But it is not just the sheer costs you should worry about. Sometimes other features/benefits may or may not outweigh the costs.
  • p

    p0

    01/01/2023, 5:10 AM
    alright
  • s

    sks

    01/01/2023, 5:14 AM
    Planet scale can give you MySQL-like benefits, and of course, you can read the data from somewhere else as well. But with DO you have to use another worker to read and write to the DO. And if you need to scale to more than 100 requests per second, DO may cause some issues, because DOs are single-threaded. Although very fast, it has a limit, because of the fact that it's single-threaded. So, for customers doing more than 1000 requests per second, (if you have such customers) then it would not be able to handle.
  • s

    sks

    01/01/2023, 5:47 AM
    We have to look at Cloudflare D1 pricing. It is a good thing, but if costs are comparative, then it would be a very good contender.
  • p

    p0

    01/01/2023, 5:48 AM
    I was looking into that. D1 isn't production ready and prices for it aren't yet released sadly.
  • s

    sks

    01/01/2023, 5:49 AM
    Yes, however, it will be shortly. But till then I guess you can just make do with Durable Objects.
  • p

    p0

    01/01/2023, 5:49 AM
    Yep
  • s

    sks

    01/01/2023, 6:04 AM
    Let me know how your implementation goes, I am trying to build a similar counter and block thing.
  • p

    p0

    01/01/2023, 11:01 AM
    @Unsmart | Tech debt for when you get online: I'm trying to use the following durable object for my use-case:
    Copy code
    javascript
    export class Counter {
        constructor(controller, env) {
            this.storage = controller.storage;
        }
    
        async initialize() {
            let stored = await this.storage.get("value");
            this.value = stored || 0;
        }
    
        async fetch() {
            if (!this.initializePromise) {
                this.initializePromise = this.initialize();
            }
            await this.initializePromise;
    
            ++this.value;
            await this.storage.put("value", this.value);
    
            return new Response(this.value);
        }
    }
    However, it isn't working as excepted. When I restart the dev server or wait a bit, the value resets back to 0. How do I fix this behavior?
  • p

    p0

    01/01/2023, 11:03 AM
    Nevermind! Solved my issue from the docs: > wrangler dev has read access to Durable Object storage, but writes will be kept in memory and will not affect persistent data. However, if you specify the script_name explicitly in the Durable Object binding, then writes will affect persistent data. Wrangler 2 will emit a warning in that case.
  • p

    p0

    01/01/2023, 12:46 PM
    @Unsmart | Tech debt is there any alternative to this madness?
  • w

    Walshy | Pages

    01/01/2023, 1:06 PM
    Don't delete and remake constantly?
  • p

    p0

    01/01/2023, 5:29 PM
    How else am I supposed to test them?
  • p

    p0

    01/01/2023, 5:32 PM
    migrations seem like a horrible solution for this imho
  • p

    p0

    01/01/2023, 5:32 PM
    there's definitely better ways to manage this
  • d

    DanTheGoodman

    01/01/2023, 6:04 PM
    Are there any suggestions for running end-user code in durable objects? I’m thinking of having a wrapper class and then importing a class they made with a set of expected methods. Will have to do a deployment for each end user. Security might also be a concern
  • d

    DanTheGoodman

    01/01/2023, 6:05 PM
    I specifically want to run in the DO to have low latency to the data
  • k

    Kai

    01/01/2023, 6:24 PM
    Testing locally works great
  • p

    p0

    01/01/2023, 6:25 PM
    Doesn't work if you want to maintain storage
  • k

    Kai

    01/01/2023, 6:25 PM
    --persist is a thing? Not sure what you mean
  • k

    Kai

    01/01/2023, 6:25 PM
    if you delete & create new storage is cleared anyways
  • p

    p0

    01/01/2023, 6:31 PM
    That's mentioned absolutely nowhere in the docs except for the wrangler commands section.
  • p

    p0

    01/01/2023, 6:32 PM
  • p

    p0

    01/01/2023, 6:33 PM
    they should definitely consider mentioning it somewhere useful to avoid people like me creating tons of spam in their config
  • k

    Kai

    01/01/2023, 6:45 PM
    sure I guess, but wrangler is the tool of choice for development, and they mention using
    wrangler dev
    for development, so idk
  • j

    jed

    01/01/2023, 7:06 PM
    i think that’s what this is for: https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/learning/how-workers-for-platforms-works/
  • d

    DanTheGoodman

    01/01/2023, 7:42 PM
    I don’t believe you can make a durable object, but you can bind one
  • j

    jed

    01/01/2023, 10:13 PM
    hmmm, i see. depending on what you need, i wonder if you could use quickjs via wasm.
  • d

    DanTheGoodman

    01/01/2023, 10:13 PM
    I don’t think wasm is supported for durable objects?
1...471472473...567Latest