Webber
Webber
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Thank you very much!
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
I see
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Meaning I should define my application routes (as well as any possible class instances) for every request - inside the fetch implementation?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Ah right. I forgot. All the more reason to already have the env before fetch is called, I'd say - right?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
One last follow-up question if you don't mind. In that case, why is env passed as part of the async fetch call? I realise that after an hour they might be a bit outdated, but is it also possible to load env manually (e.g. periodically)? Consider some code like:
app = expressLike(/* some elaborate application that needs `env` */)

export default {
async fetch(req, env, ctx) {
app.handle(req)
}
}
app = expressLike(/* some elaborate application that needs `env` */)

export default {
async fetch(req, env, ctx) {
app.handle(req)
}
}
Is there some good practice in handling env variables in cases like this?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Awesome!
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
So in case of no rollout, but regular use, if I get a request every 5 seconds (and each request still takes 25 seconds to complete), the instance will be longer lived than 30 seconds. Is that also correct?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
I see. Very cool
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Or put differently: Am I guaranteed that every request to any (unbound) worker instance will always have 30 seconds to be handled?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Ok that makes sense. However I would still like to know how a request that starts after 10 seconds would work. Does it mean the traffic to that worker instance gets rerouted to a new worker, and the request would be fine as long as it also completes in 25 seconds?
13 replies
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
Does that mean every user request gets its own worker instance / v8 Isolate for every request?
13 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
TL;DR: After a lot of debugging I've managed to get a fully working email worker. https://github.com/webbertakken/email-worker Note that even though the worker is fully functional, the dashboard view of email workers is still bugged. The only thing that solves that issue is to manually change from
var src_default = { email };
export {
src_default as default,
email
};
var src_default = { email };
export {
src_default as default,
email
};
to
export default { email }
export default { email }
I'm really hoping this helps CF easily solve this issue. Or at least helps other people facing the same problem wasting a lot less time by reading this.
10 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
Agreed. The operative word here being "should". That's why I mentioned it's likely a bug.
10 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
I've also tried Vercel NCC, which uses Webpack. Same result.
10 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
Also tried using this template https://github.com/cloudflare/miniflare-typescript-esbuild-jest which uses ESBuild. I've added a minimal method like so:
// @ts-ignore
import PostalMime from 'postal-mime';

...handleRequest...

export async function email(message: any, env: any, ctx: any): Promise<void> {
console.log(message.from);

const rawBody = await new Response(message.raw).arrayBuffer();
const parser = await new PostalMime();
const email = await parser.parse(rawBody);

console.log(email.from);
}

const worker = { fetch: handleRequest, email };
export default worker;
// @ts-ignore
import PostalMime from 'postal-mime';

...handleRequest...

export async function email(message: any, env: any, ctx: any): Promise<void> {
console.log(message.from);

const rawBody = await new Response(message.raw).arrayBuffer();
const parser = await new PostalMime();
const email = await parser.parse(rawBody);

console.log(email.from);
}

const worker = { fetch: handleRequest, email };
export default worker;
Which has exactly the same result. Definitely looks like something is broken on CF side
10 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
If only it compiled to
async function email(message, env, ctx) {
console.log(message.from);
}

export default { email }
async function email(message, env, ctx) {
console.log(message.from);
}

export default { email }
It would simply work (note the default part).
10 replies