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

    Unsmart | Tech debt

    04/28/2023, 4:03 AM
    They are stored forever or until deleted
  • b

    bret_pat

    04/28/2023, 4:05 AM
    I asked about pricing for storage and it's below
  • b

    bret_pat

    04/28/2023, 4:07 AM
    Ohhh i see the table now
  • b

    bret_pat

    04/28/2023, 4:07 AM
    https://developers.cloudflare.com/workers/platform/pricing/#durable-objects is my answer
  • a

    Akarys

    04/29/2023, 6:44 PM
    so cool, wrangler asks me to navigate to
    https://dash.cloudflare.com/$id/workers/overview?enable-durable-objects
    , except that doesn't bring up any modal or anything
  • a

    Akarys

    04/29/2023, 6:44 PM
    what's the correct url?
  • j

    James

    04/29/2023, 6:57 PM
    Are you on the paid version of Workers? I believe that's all that's necessary these days: https://developers.cloudflare.com/workers/learning/using-durable-objects/#using-durable-objects-1
  • s

    sathoro

    05/01/2023, 4:10 AM
    hey, does anyone know why I get
    Unhandled Promise Rejection: TypeError: this.state.blockConcurrencyWhile is not a function
    when using
    itty-durable
    ? I thought I should be able to access it:
  • s

    sathoro

    05/01/2023, 4:11 AM
    oh yeah this is being called from within an alarm. maybe that is the problem
  • s

    Starlin

    05/02/2023, 4:52 AM
    Hi, we would like to use durable objects in our project, after deploying i dont see durable objects in worker. toml file:
    Copy code
    [durable_objects]
    bindings = [{name = "COUNTER1", class_name = "Counter"}]
    durable object reference:
    Copy code
    let id = env.COUNTER1.idFromName(requestIp);
    let obj = env.COUNTER1.get(id);
    let resp = await obj.fetch(request.url);
    let count = parseInt(await resp.text())
    Durable object class:
    Copy code
    export class Counter {
      state: any;
      constructor(state:any) {
        this.state = state;
      }
      async fetch(request:any) {
        // Apply requested action.
        let url = new URL(request.url);
        let value = await this.state.storage.get("value") || 0;
        ++value;
        await this.state.storage.put("value", value);
        return new Response(value);
      }
    }
    binding.ts:
    COUNTER1: DurableObjectNamespace;
    Error after deploying using wrangler publish: ✘ [ERROR] TypeError: Cannot read properties of undefined (reading 'idFromName') can someone help here?
  • h

    HardAtWork

    05/02/2023, 6:14 AM
    Does it show the DO binding when you run publish?
  • s

    Starlin

    05/02/2023, 6:43 AM
    no, DO binding also not shown
  • d

    Dani Foldi

    05/02/2023, 6:56 AM
    You're missing a
    migrations
    entry that you need when you define, rename or remove a DO class Add this to the end of wrangler.toml:
    Copy code
    toml
    [[migrations]]
    tag = ''
    new_classes = ['Counter']
  • s

    Starlin

    05/02/2023, 7:36 AM
    after adding [[migrations]], i see binding created but still same error when worker runs.
    ✘ [ERROR]   TypeError: Cannot read properties of undefined (reading 'idFromName')
  • d

    Dani Foldi

    05/02/2023, 7:37 AM
    hmm, could you share more of your worker code?
  • s

    Starlin

    05/02/2023, 7:40 AM
    Copy code
    public static async processRequest(request: Request, env: Bindings): Promise<Response> {
            const requestIp:string | null  = request.headers.get('CF-Connecting-IP');
            const requestUrl:string = request.url;
            
            //const list = await env.test_kv_binding.list({});
            if(requestIp && requestUrl.includes("test url")) {
                if(requestIp) {
                    let id = env.COUNTER1.idFromName(requestIp); //facing error here
                    let obj = env.COUNTER1.get(id);
                    let resp = await obj.fetch(request.url);
                    let count = parseInt(await resp.text())
                    console.log('count : ', count);
                }
    }
    binding.ts:
    Copy code
    interface Bindings {
        COUNTER1: DurableObjectNamespace;
    }
    index.ts
    Copy code
    import { RequestDomain } from './request/request.domain';
    
    export async function handleRequest(request: Request, env: Bindings) {
      return await RequestDomain.processRequest(request, env);
    }
    
    export class Counter {
      state: any;
      constructor(state:any) {
        this.state = state;
      }
    
      async fetch(request:any) {
        let url = new URL(request.url);
        let value = await this.state.storage.get("value") || 0;
        ++value;
        await this.state.storage.put("value", value);
    
        return new Response(value);
      }
    }
    
    const worker: ExportedHandler<Bindings> = { fetch: handleRequest };
    
    export default worker;
  • d

    Dani Foldi

    05/02/2023, 7:48 AM
    hmm, I didn't see anything right away, let me check something
  • s

    Starlin

    05/02/2023, 7:54 AM
    ok
  • d

    Dani Foldi

    05/02/2023, 8:05 AM
    Your worker code seems fine, are you using environments by any chance? (That would be
    --environment prod
    , for example, when deploying)
  • s

    Starlin

    05/02/2023, 8:10 AM
    yes wrangler publish -e DEV
  • d

    Dani Foldi

    05/02/2023, 8:11 AM
    and do you have the
    durable_objects.bindings = []
    under the env definition? Bindings don't get inherited
  • s

    Starlin

    05/02/2023, 8:12 AM
    yes my env file below name = "cf_interceptor_dev" main = "dist/index.mjs" account_id = "xx" workers_dev = true compatibility_date = "2022-05-28" compatibility_flags = [] [env.DEV] name = "cf_interceptor_dev" workers_dev = false kv_namespaces = [ { binding = "test_kv_binding", id = "xx" } ] [durable_objects] bindings = [{name = "COUNTER1", class_name = "Counter1"}] routes = [] [env.DEV.vars] WEB_APP_DOMAIN='test' [build] command = "node build.js" [[migrations]] tag = '' new_classes = ['Counter1']
  • d

    Dani Foldi

    05/02/2023, 8:13 AM
    yup, so if you define it as [durable_objects], that's no longer under [env.DEV], but it's own thing
  • d

    Dani Foldi

    05/02/2023, 8:14 AM
    so you can either do [env.DEV.durable_objects], just like you have with vars, or do
    durable_objects.bindings
    instead of
    bindings
  • s

    Starlin

    05/02/2023, 8:16 AM
    my bad, it works great now. thanks a lot for the help @Dani Foldi
  • d

    Dani Foldi

    05/02/2023, 8:17 AM
    Glad you got it working, happy to help!
  • s

    sathoro

    05/02/2023, 2:57 PM
    are durable object value size limits enforced when developing locally? either they are not or I don't understand the size limit
  • u

    Unsmart | Tech debt

    05/02/2023, 2:57 PM
    they should be afaik
  • u

    Unsmart | Tech debt

    05/02/2023, 2:57 PM
    you can always deploy and see if it doesnt allow the same as local 🤷
  • s

    sathoro

    05/02/2023, 3:00 PM
    Copy code
    js
    console.log("SIZE", JSON.stringify(await queueStub.toJSON()).length);
    output: SIZE 134275 shouldn't be possible, right? that is using itty-durable which stores the whole value in a single "field"
1...543544545...567Latest