Webber
Webber
CDCloudflare Developers
Created by Webber on 7/8/2023 in #workers-help
How does worker max time work precisely?
What (I think) I understand: - When using paid plan, you can make use of either Bundled or Unbound worker runtime. - In case of Unbound, the worker can last for a maximum of 30 seconds. - It can serve 6 multiple connections as the same time What I'm trying to figure out: - If my request takes 25 seconds to process, should I return a response immediately or after those 25 seconds? - How do I prevent a second reqeust from coming in after 5 seconds (at which point there isn't enough time to process the request during max runtime of the worker)? Most likely my mental model is somehow wrong, would love to learn!
13 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
Wrangler compiling in an incompatible way?
As mentioned here https://discord.com/channels/595317990191398933/846453104382836766/1079084350437589063 I'm using wrangler to publish a worker, but there seems to be a bug. In my code index.ts I export default like so
export default { email };
export default { email };
When using wrangler publish it compiles to:
var src_default = { email };
export {
src_default as default
};
var src_default = { email };
export {
src_default as default
};
And in the dashboard when I try to test it it tells me
Email Trigger not available to this workers
Email Trigger not available to this workers
Though when I change it manually to the former again:
export default { email };
export default { email };
It seems to work and goes to the next error about a constructor. Changing the tsconfig.json file doesn't seem to make any difference at all. Looks like a bug to me. Any ideas of what I can try?
10 replies
CDCloudflare Developers
Created by Webber on 2/25/2023 in #workers-help
How to spy on mocked fetch interceptor?
Given the following mock (which is amazing by the way):
// Disable Fetch API from making real network requests
// @see https://undici.nodejs.org/#/docs/api/MockAgent?id=mockagentdisablenetconnect
const fetchMock = getMiniflareFetchMock();
fetchMock.disableNetConnect();

// Intercept calls to Discord's webhook API
const origin = fetchMock.get('https://discord.com');
origin.intercept({ method: 'POST', path: /api\/webhooks\/.*/ }).reply(200, 'Mocked response!');
// Disable Fetch API from making real network requests
// @see https://undici.nodejs.org/#/docs/api/MockAgent?id=mockagentdisablenetconnect
const fetchMock = getMiniflareFetchMock();
fetchMock.disableNetConnect();

// Intercept calls to Discord's webhook API
const origin = fetchMock.get('https://discord.com');
origin.intercept({ method: 'POST', path: /api\/webhooks\/.*/ }).reply(200, 'Mocked response!');
How do I spy on it and then check how often it's called?
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledTimes(1)
4 replies
CDCloudflare Developers
Created by Webber on 2/22/2023 in #workers-help
Any ideas how to get worker constructors into Vitest?
3 replies
CDCloudflare Developers
Created by Webber on 2/22/2023 in #workers-help
Email worker template?
From the email workers documentation there's a nice description of how to create a worker. https://developers.cloudflare.com/email-routing/email-workers/ Trying to start a project I'm looking for a typescript template or simply the types. The page links to languages: https://developers.cloudflare.com/workers/platform/languages/ Which links to: https://github.com/cloudflare/workers-types Which is archived - types now live in workerd (which is a C++ repo): https://github.com/cloudflare/workerd From there it's unclear how to use types for email workers in your project. So from following that path it's unclear: How to include the types? And if the answer is "use the regular worker typescript template", that's fine too. Perhaps it would be nice to see this reflected in the docs - I'd be happy to submit a PR for that.
9 replies