https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • k

    Kevin W - Itty

    04/17/2023, 2:24 PM
    Thanks @kian - I'll give that a go. Any way to grab the history of all active Workers at once?
  • u

    Unsmart | Tech debt

    04/17/2023, 2:48 PM
    dont provide the worker name in the query filter and set the worker name as a dimension
  • u

    Unsmart | Tech debt

    04/17/2023, 2:51 PM
    Something like this:
    Copy code
    gql
    query {
      viewer {
        accounts(filter: {
          accountTag: "<put ur account id here>"
        }) {
          workersInvocationsAdaptive(
            filter: {
              date_geq: "2023-03-01",
              date_leq: "2023-03-31"
            },
            limit: 10000,
            orderBy: [sum_requests_DESC]
          ) {
            dimensions {
              scriptName
            }
            sum {
              requests
              wallTime
            }
          }
    
        }
      }
    }
  • u

    Unsmart | Tech debt

    04/17/2023, 2:56 PM
    If you have any unbound workers the wallTime is microseconds iirc. Multiplying by
    0.000000125
    should get you the GB-sec value
  • k

    Kevin W - Itty

    04/17/2023, 3:21 PM
    Thanks!
  • s

    stackiflow

    04/17/2023, 3:45 PM
    Hi everyone, does anyone know where is
    unsafe
    documented? As in
    Copy code
    [unsafe.metadata.placement]
    mode = "smart"
    from https://developers.cloudflare.com/workers/platform/smart-placement/#enable-smart-placement-beta Because I'm getting this error and I can't make any sense of it.
    Copy code
    ▲ [WARNING] Processing wrangler.toml configuration:
    
        - "unsafe" fields are experimental and may change or break at any time.
        - "env.dev" environment configuration
          - "unsafe" exists at the top level, but not on "env.dev".
            This is not what you probably want, since "unsafe" is not inherited by environments.
            Please add "unsafe" to "env.dev".
    
    
    
    ✘ [ERROR] Processing wrangler.toml configuration:
    If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose
    
        - The field "unsafe" is missing the required "bindings" property.
  • w

    Walshy | Pages

    04/17/2023, 3:47 PM
    looks like you're trying to use smart placement in the dev env, is that right?
  • w

    Walshy | Pages

    04/17/2023, 3:47 PM
    If so, you'll want the heading to be
    [env.dev.unsafe.metadata.placement]
  • w

    Walshy | Pages

    04/17/2023, 3:47 PM
    (toml sucks)
  • k

    kian

    04/17/2023, 3:47 PM
    That error looks like an old version of Wrangler
  • k

    kian

    04/17/2023, 3:47 PM
    > The field "unsafe" is missing the required "bindings" property.
  • k

    kian

    04/17/2023, 3:48 PM
    That validation was removed in 2.12.0 - hence this
  • s

    stackiflow

    04/17/2023, 3:59 PM
    I'm not sure, I'm pretty new to this. I'm using the exact same code from the documentation
    Copy code
    [unsafe.metadata.placement]
    mode = "smart"
    there's a
    [dev]
    section above and some other things below. Does that count as "in the dev env"?
  • s

    stackiflow

    04/17/2023, 4:00 PM
    So I guess updating wrangler is the first step to fix this
  • i

    ianh

    04/17/2023, 5:49 PM
    is using @cloudflare/workers-types the preferred way to support TS in workers?
  • k

    kian

    04/17/2023, 5:51 PM
    Yup
  • i

    ianh

    04/17/2023, 5:54 PM
    Where is WebSocketPair imported from? All ws examples error on TS: Cannot find name 'WebSocketPair'
  • i

    ianh

    04/17/2023, 5:54 PM
    ah, do we have to hack our types.d.ts file? https://github.com/cloudflare/workers-types/issues/84
  • i

    ianh

    04/17/2023, 5:55 PM
    seems to work but I hate monkeypatching. Will TS be get first-class support in workers?
  • k

    kian

    04/17/2023, 6:00 PM
    It’s just in workers-types already
  • k

    kian

    04/17/2023, 6:00 PM
    That’s a pretty old issue
  • h

    HardAtWork

    04/17/2023, 6:03 PM
    It is: https://gist.github.com/helloimalastair/126e8c64963aeafc27c7c1136583dda3#file-cf-d-ts-L1819
  • i

    ianh

    04/17/2023, 6:08 PM
    yeah - this is the only way I can get TS to not error, have to monkeypatch. By default any ts file will complain that youre trying to instantiate WebSocketPair which is a type
  • h

    HardAtWork

    04/17/2023, 6:09 PM
    VSCode doesn't appear to throw any errors:
  • h

    HardAtWork

    04/17/2023, 6:09 PM
    In a TS file
  • h

    HardAtWork

    04/17/2023, 6:10 PM
    What version are you running?
  • i

    ianh

    04/17/2023, 6:11 PM
    of ts? or wrangler? or cf types?
  • h

    HardAtWork

    04/17/2023, 6:11 PM
    CF Types
  • k

    Kaelten

    04/17/2023, 6:12 PM
    So I see that you can modify the response headers if you await the origin response and then return it. However, is that a good idea to do when the response could be a multi-GB file?
  • i

    ianh

    04/17/2023, 6:12 PM
    "@cloudflare/workers-types": "^4.20230404.0",
1...240124022403...2509Latest