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

    brett

    05/11/2021, 1:43 PM
    But either way you should see your updated KV value everywhere after about 60 seconds. If you were hitting a non-existent key before you created it, that's equivalent to an update, the empty value itself will be cached in colos. So it depends what your test intended to... test, often an app won't even know what key to try and fetch until it has been created and shared via some other means, and in that case it should be instantly available (since it won't have been cached as a miss anywhere)
  • v

    vans163

    05/11/2021, 1:51 PM
    Yea 60sec for us is way too long. Maybe if there was a way to instruct a browser page to always hit the same colo?
  • b

    brett

    05/11/2021, 1:52 PM
    Are you actually updating existing keys containing these videos in your app? Or are they stable once created?
  • w

    Wallacy

    05/11/2021, 3:15 PM
    Im pretty sure that violate the TOS 2.8;
  • w

    Wallacy

    05/11/2021, 3:15 PM
    If not i will glad to be corrected.
  • v

    vans163

    05/11/2021, 3:16 PM
    Yea right it's against rules i thought so too
  • v

    vans163

    05/11/2021, 3:17 PM
    I tested on updates on a totally unrelated project.
  • v

    vans163

    05/11/2021, 3:17 PM
    In this project I would not be updating existing keys
  • w

    Wallacy

    05/11/2021, 3:24 PM
    I wanted to do this for one of my projects. But even on Enterprise plan i could not get a good deal on high bandwidth video traffic. But you can get good bandwidth fees using some EU providers, my Workers redirect the traffic to those points using 307 redirects when video files.
  • w

    Wallacy

    05/11/2021, 3:25 PM
    I want make full use of cloudflare but those "american" bandwidth fees is not for our budget;
  • w

    Wallacy

    05/11/2021, 3:40 PM
    Anyway.... Im testing DO for the past month, except the problem with traffic, on the technical side i have few questions: -- All wrangler args for DO like --new-class, --delete-class are a pain in the ass for our CI/CD; Its should be make implicity using the information on the wrangler.tom. The old bash script using rest API was better on that; -- On KV we can just look for the data stored using the panel, wrangler, or any other worker. But for DO its hard do debug the data on storage api. Will be nice have a way to query that storage using wrangler tail,/dev/whatever without make a custom route for that. -- Is the schedule on DO working? i make a regular worker with schedule just to call a DO because of that. -- Theres any plan to expose the DO without a regular worker in front? -- For worker to DO call: Any plan to call using request/import like any regular JS class without the fetch? Thats make everything less susceptible an error and can be internally optimized on when both are at same colo.
  • g

    Gavin

    05/12/2021, 1:13 PM
    how do you use cron triggers with modules? do we just export a ScheduledEvent handler along with the fetch handler? if so, what arguments does it need?
  • d

    Deebster

    05/12/2021, 3:06 PM
    I'm assuming you can use just a
    scheduled(request: ScheduledEvent, env)
    handler if that module only handles crons. https://github.com/cloudflare/workers-types/blob/master/index.d.ts says you should expect > interface ScheduledEvent { > /** > * The type of event. This will always return
    "scheduled"
    . > */ > type: string; > /** > * The time the
    ScheduledEvent
    was scheduled to be executed in > * milliseconds since January 1, 1970, UTC. > * It can be parsed as
    new Date(event.scheduledTime)
    > */ > scheduledTime: number; > /** > * Use this method to notify the runtime to wait for asynchronous tasks > * (e.g. logging, analytics to third-party services, streaming and caching). > * The first
    event.waitUntil
    to fail will be observed and recorded as the > * status in the Cron Trigger Past Events table. Otherwise, it will be > * reported as a Success. > */ > waitUntil(promise: Promise): void; > }
  • g

    Gavin

    05/12/2021, 3:08 PM
    awesome. thank you! is there anyway to distinguish between cron triggers in code? like have one every minute that does a small amount of work and another every day that does some big task?
  • d

    Deebster

    05/12/2021, 3:14 PM
    Huh, good question. I can't see anything that distinguishes crons from each other, and you can't pass in a url or per-cron env that I can see... I can't see anything in the docs so I'd say no, but you should definitely ask someone who actually knows what they're talking about 😄
  • e

    eidam | SuperSaaS

    05/12/2021, 3:22 PM
    There should be string of the cron schedule available
  • g

    Gavin

    05/12/2021, 3:56 PM
    so you can use that string to id the job then i guess. you just can't have 2 triggers with the same schedule and do that
  • d

    Deebster

    05/13/2021, 3:58 AM
    Does the environment parameter have a typescript definition in worker-types? Or is it just a plain object with no methods and only the fields you define?
  • g

    Gavin

    05/13/2021, 7:52 AM
    i just use "any" for that
  • j

    JuicyIce

    05/13/2021, 9:08 AM
    Hey guys, anyone have any idea why I can't get Websockets to connect? I'm using the CF chat example. Here's the code Durable Object side:
    Copy code
    let url = new URL(request.url);
                
                switch (url.pathname) {
                    case '/connect-websocket':
                        if (request.headers.get('Upgrade') !== 'websocket') {
                            return new Response('expected websocket', {status: 400});
                        }
                        
                        let ip = request.headers.get('CF-Connecting-IP');
                        let pair = new WebSocketPair();
                        
                        await this.handleSession(pair[1], ip);
                        
                        return new Response(null, {status: 101, webSocket: pair[0]})
                        break;
                    case '/init-data':
                        this.data = await request.json();
                        
                        return new Response(JSON.stringify({message: 'Data initialized'}), {headers: corsHeaders});
                        break;
                    default:
                        return new Response('Not found', {status: 404});
                }
    Client side:
    Copy code
    this.websocketConnection = new WebSocket('wss://secretdomain/connect-websocket?userId=20');
            this.websocketConnection.addEventListener('error', (err) => {
                console.log(err);
            });
    
            this.websocketConnection.addEventListener('open', (event) => {
                console.log(event);
            });
    The only error I get is WebSocket connection to blabla failed Btw I can make an HTTP request just fine. Have tried to debug this for several hours 😄
  • j

    JuicyIce

    05/13/2021, 9:08 AM
    Handle session is like this:
    Copy code
    async handleSession(webSocket, ip) {
            webSocket.accept();
            
            webSocket.addEventListener('message', async (message) => {
                try {
                    this.siteData = message.data;
                } catch (e) {
                    console.log(e);
                }
            })
        }
  • j

    JuicyIce

    05/13/2021, 10:20 AM
    Okay found the issue, don't mind the post above 😄 🤦‍♂️
  • e

    Erwin

    05/13/2021, 10:56 AM
    Don't think it has anything else but your bindings. But I have never actually checked.. Only ever used it for that..
  • t

    taro

    05/13/2021, 5:39 PM
    for clarification, will lookups using IDs derived from
    idFromName
    always be slower than lookups using IDs created with
    newUniqueId
    ?
  • t

    taro

    05/13/2021, 5:40 PM
    I understand that this is the case upon creating a DO for the first time, however, I'm still unsure about later instantiations of DOs
  • e

    eidam | SuperSaaS

    05/13/2021, 7:04 PM
    This is nice, DO limits documented, inc. WebSockets and CPU limit ❤️ https://developers.cloudflare.com/workers/platform/limits#durable-objects
  • v

    vans163

    05/13/2021, 7:45 PM
    @User how does that 500ms per request CPU time work if the request sets off a setTimeout?
  • v

    vans163

    05/13/2021, 7:46 PM
    How does one handle crons with the new ES6 class syntax
    Copy code
    export default {
      async fetch(request, env) { ... }
      async scheduled(scheduledevent, env) { .. }
    }
    ?
  • v

    vans163

    05/13/2021, 7:57 PM
    how can I have scheduled and fetch in same export?
  • v

    vans163

    05/13/2021, 7:57 PM
1...838485...567Latest