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

    IdkWhatever69

    05/27/2023, 6:51 PM
    from where?
  • w

    Walshy | Pages

    05/27/2023, 6:52 PM
    tail or if you have logpush enabled then they'll be in your storage
  • i

    IdkWhatever69

    05/27/2023, 6:52 PM
    logpushs are paid right?
  • w

    Walshy | Pages

    05/27/2023, 6:53 PM
    it requires a paid plan iirc but the feature itself isn't paid
  • s

    silence

    05/27/2023, 6:54 PM
    For now i solved this by using queues and service workers, really hacky. how hard is it to get a limit increase?
  • i

    IdkWhatever69

    05/27/2023, 6:54 PM
    this project is for public service i cant put any money into this :{

    https://cdn.discordapp.com/attachments/779390076219686943/1112091451568951346/Screenshot_2023-05-28_at_12.23.54_AM.png▾

  • w

    Walshy | Pages

    05/27/2023, 6:54 PM
    oh nevermind but it's very cheap 10 mil included then only $0.05/mil (after filtering)
  • w

    Walshy | Pages

    05/27/2023, 6:54 PM
    best you'd get is tail then
  • w

    Walshy | Pages

    05/27/2023, 6:55 PM
    it'll fire again in 6 mins so start tailing now and wait 6 mins
  • i

    IdkWhatever69

    05/27/2023, 6:55 PM
    so just
    wrangler tail
    right?
  • w

    Walshy | Pages

    05/27/2023, 6:56 PM
    yep
  • i

    IdkWhatever69

    05/27/2023, 7:05 PM
    this time it worked. its the exact static code... what kinda blackmagic fookery is this
  • w

    Walshy | Pages

    05/27/2023, 7:06 PM
    what's the code doing?
  • w

    Walshy | Pages

    05/27/2023, 7:06 PM
    do you make a request to a service or anything?
  • i

    IdkWhatever69

    05/27/2023, 7:06 PM
    yes actually
  • w

    Walshy | Pages

    05/27/2023, 7:06 PM
    so probably that service returned something unexpectedly
  • i

    IdkWhatever69

    05/27/2023, 7:06 PM
    its open source so here you go: https://github.com/DaBigBlob/FIT-Weather-Chan/blob/main/src/bot.ts
  • i

    IdkWhatever69

    05/27/2023, 7:07 PM
    the requests are these:
    Copy code
    ts
    //get hourly weather
        const wthr: Result<Period> = await (async () => {
            const proto_res = (await (await fetch(`${WeatherAPIEndpoint}/hourly`, { body: null, method: 'GET', headers: fetch_headers})).json()) as WeatherData|undefined;
            if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}/hourly`);
    
            const result = proto_res.properties.periods.filter(p => (dateIsoToUnixSec(p.startTime)*1000 > now))[0];
            if (exists(result)) return new Ok(result);
    
            return new Err("Data too old");
        })();
        if (!wthr.isOk()) return;
    
        //get overall day dorcast
        const day_forcase = await (async () => {
            const proto_res = (await (await fetch(WeatherAPIEndpoint, { body: null, method: 'GET', headers: fetch_headers})).json()) as WeatherData|undefined;
            if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}`);
    
            const result = proto_res.properties.periods.find(p => (p.number == 1));
            if (exists(result)) return new Ok(result);
    
            return new Err("Today's data not found");
        })();
  • i

    IdkWhatever69

    05/27/2023, 7:07 PM
    my god that looks ugly
  • i

    IdkWhatever69

    05/27/2023, 7:08 PM
    (excuse my spelling mistakes)
  • j

    James

    05/27/2023, 7:10 PM
    Yeah you're making a lot of assumptions about those requests always returning a 200, and always returning valid JSON
  • j

    James

    05/27/2023, 7:10 PM
    I'd guess one of them had a hiccup
  • j

    James

    05/27/2023, 7:11 PM
    If you wanted to make it more resilient,, make the request, check if OK, check if JSON, and then call
    .json()
  • j

    James

    05/27/2023, 7:11 PM
    Depending on the service, I might also check the data is returns, in case there's a chance
    properties.periods
    doesn't exist, for example.
  • f

    F0rce

    05/27/2023, 7:12 PM
    is
    Copy code
    toml
    [placement]
    mode = "smart"
    inheritable ? The docs page does not seem to have it listed.
  • i

    IdkWhatever69

    05/27/2023, 7:16 PM
    right i should check .ok before .json()-ing
  • i

    IdkWhatever69

    05/27/2023, 7:17 PM
    Copy code
    ts
    if (!exists(proto_res) || !exists(proto_res.properties.periods)) return new Err(`No data from ${WeatherAPIEndpoint}/hourly`);
    i do check that
  • j

    James

    05/27/2023, 7:17 PM
    yep I'd check
    .ok
    and also check if the
    content-type
    includes
    application/json
    . You'd be surprised at how many APIs are wonky sometimes and return a 200 but an HTML error page or something
  • j

    James

    05/27/2023, 7:18 PM
    if
    .properties
    doesn't exist there, you'll get a
    TypeError
    . I'd check
    proto_res.properties
    exists too
  • i

    IdkWhatever69

    05/27/2023, 7:18 PM
    but this is in the geaders tho
    Copy code
    ts
    const fetch_headers = {
        'User-Agent': `${fitweather_credentials.name}/1.0 (Florida Institute of Technology Weather Discord Bot (Student Run), https://github.com/DaBigBlob/FIT-Weather-Chan)`,
        'Accept': "application/geo+json"
    };
1...250425052506...2509Latest