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

    vans163

    04/11/2021, 7:19 PM
    if code inside a DO crashes
  • v

    vans163

    04/11/2021, 7:19 PM
    does the whole DO restart and loses its local state?
  • v

    vans163

    04/11/2021, 9:41 PM
    how does one use KV for workers inside a DO
  • v

    vans163

    04/11/2021, 9:41 PM
    i keep getting its not defined
  • v

    vans163

    04/11/2021, 9:41 PM
    i think i attached the KV using the web gui not wrangler
  • v

    vans163

    04/11/2021, 9:42 PM
    could it be bugged?
  • v

    vans163

    04/11/2021, 9:42 PM
    i cant detach it
  • v

    vans163

    04/11/2021, 10:06 PM
    is there any chance to get metadata on durable object storage same to Worker KV?
  • v

    vans163

    04/11/2021, 10:06 PM
    that metadata makes it really easy to paginate with filters
  • v

    vans163

    04/11/2021, 10:06 PM
    not only easy, but possible
  • v

    vans163

    04/11/2021, 10:07 PM
    some more complex filters are impossible to list with the current way DOs work. because you cannot properly place start
  • v

    vans163

    04/11/2021, 10:18 PM
    a way to get only the keys would be nice too
  • v

    vans163

    04/11/2021, 10:25 PM
    the problem is kinda ths
  • v

    vans163

    04/11/2021, 10:25 PM
  • v

    vans163

    04/11/2021, 10:25 PM
    so if I wanna paginate via list
  • v

    vans163

    04/11/2021, 10:26 PM
    with limit of 100
  • v

    vans163

    04/11/2021, 10:26 PM
    each read will readback full object, thats 100 reads for 1 list?
  • v

    vans163

    04/11/2021, 10:26 PM
    vs the KV worker storage, list had its own cost
  • v

    vans163

    04/11/2021, 10:57 PM
    i guess I am asking if this function will cost a fortune
    Copy code
    javascript
      async get_jobs_by_filter({queued, in_progress, finished, failed}, page, limit, acc, offset) {
        offset = offset || 0
        acc = acc || []
        var objects = await this.storage.list({start: offset, limit: 1000})
        var jobs = objects.values.filter(job=> {
            if (queued && job.status == "queued")
              return true;
            if (in_progress && job.status == "in_progress")
              return true;
            if (finished && job.status == "done")
              return true;
            if (failed && job.status == "error")
              return true;
            return false
        })
        acc = acc.concat(jobs);
    
        //abort early
        var skip = page*limit
        if (acc.length >= skip+limit) {
            return acc.slice(skip, limit)
        }
    
        if (objects.size == 1000) {
            return get_jobs_by_filter({queued, in_progress, finished, failed}, page, limit, acc, offset + 1000)
        } else {
            return acc.slice(skip, limit)
        }
      }
  • v

    vans163

    04/11/2021, 10:58 PM
    size of key 32bytes size of value around 8kb
  • v

    vans163

    04/11/2021, 11:03 PM
    on KV Worker i just set the 4 boolean filters as metadata
  • v

    vans163

    04/11/2021, 11:03 PM
    i dont want to use KV worker with DO because its inconsistent, soemtimes KVWorker updates instantly, other time takes 15 seconds
  • l

    luke

    04/12/2021, 1:25 AM
    Thanks, that did the trick!
  • l

    luke

    04/12/2021, 2:13 AM
    @User having some trouble getting the sites template to work with type=javascript and upload_format=modules:
    __STATIC_CONTENT is not defined
    . kv-asset-handler seems to depend on some globals that are available in the webpack environment but not javascript + modules format for some reason. is this something i can resolve on my own, or is there magic happening behind the scenes?
  • l

    luke

    04/12/2021, 2:30 AM
    https://github.com/lukeburns/worker-sites-template
  • l

    luke

    04/12/2021, 3:10 AM
    Ah looks like
    __STATIC_CONTENT
    is passed through the
    env
    argument for module workers
  • l

    luke

    04/12/2021, 4:30 AM
    After updating kv-asset-handler to use
    env
    instead, I now get the error:
    there is no KV namespace bound to the script
    , so I think something behind the scenes may have to change.
  • l

    luke

    04/12/2021, 4:30 AM
    env.__STATIC_CONTENT
    is defined, but it's an empty object.
  • g

    GrygrFlzr

    04/12/2021, 11:43 AM
    @User any plans to make it easily mockable for dev, or should I mock on top of itty durables?
  • p

    PhilipA

    04/12/2021, 11:56 AM
    Pretty sure I had this same issue a month or so ago as I am using the new module format for both worker and DO - I ended up having to make quite a few (workaround) changes to kv-asset-handler, including creating my own version of the manifest and passing that as an option to getAssetFromKV. Newer versions of wrangler may fix that issue somewhat.
1...555657...567Latest