Sure, I can share some pieces that I

Sure, I can share some pieces that I reckon is relevant. Appreciate your help. I did deploy the worker, yes. wrangler.toml
[[workflows]]
name = "process-incoming-emails"
binding = "PROCESS_INCOMING_EMAILS_WORKFLOW"
class_name = "ProcessIncomingEmailsWorkflow"
[[workflows]]
name = "process-incoming-emails"
binding = "PROCESS_INCOMING_EMAILS_WORKFLOW"
class_name = "ProcessIncomingEmailsWorkflow"
types.ts
import type { Workflow } from '@cloudflare/workers-types';

export type Bindings = {
// ...other bindings
PROCESS_INCOMING_EMAILS_WORKFLOW: Workflow;
};
import type { Workflow } from '@cloudflare/workers-types';

export type Bindings = {
// ...other bindings
PROCESS_INCOMING_EMAILS_WORKFLOW: Workflow;
};
src/index.ts
import { app } from './app'; // Hono app
import type { Bindings } from './types';
import { handleForwardingIncomingEmails } from './incoming-emails/forward-email-handler';

export { ProcessIncomingEmailsWorkflow } from './incoming-emails/workflow';

const handler = {
fetch: app.fetch,
async email(message, env, ctx) {
await handleForwardingIncomingEmails(message, env, ctx);
},
} satisfies ExportedHandler<Bindings>;
import { app } from './app'; // Hono app
import type { Bindings } from './types';
import { handleForwardingIncomingEmails } from './incoming-emails/forward-email-handler';

export { ProcessIncomingEmailsWorkflow } from './incoming-emails/workflow';

const handler = {
fetch: app.fetch,
async email(message, env, ctx) {
await handleForwardingIncomingEmails(message, env, ctx);
},
} satisfies ExportedHandler<Bindings>;
./incoming-emails/forward-email-handler
export const handleForwardingIncomingEmails = async (
message: ForwardableEmailMessage,
env: Bindings,
_ctx: ExecutionContext,
) => {
return withLogTags(
{
tags: {
handler: 'email',
requestId: crypto.randomUUID(),
},
},
async () => {
const [address] = addressParser(message.to);

if (!address?.address) {
logger.warn('No email address found in `to` field');
return message.setReject('No email address found in `to` field');
}

logger.log('Workflow defined', {
defined: !!env.PROCESS_INCOMING_EMAILS_WORKFLOW, // <-- Not defined here!
});

// await env.PROCESS_INCOMING_EMAILS_WORKFLOW.create({
// params: {
// message,
// },
// });
}
)
}
export const handleForwardingIncomingEmails = async (
message: ForwardableEmailMessage,
env: Bindings,
_ctx: ExecutionContext,
) => {
return withLogTags(
{
tags: {
handler: 'email',
requestId: crypto.randomUUID(),
},
},
async () => {
const [address] = addressParser(message.to);

if (!address?.address) {
logger.warn('No email address found in `to` field');
return message.setReject('No email address found in `to` field');
}

logger.log('Workflow defined', {
defined: !!env.PROCESS_INCOMING_EMAILS_WORKFLOW, // <-- Not defined here!
});

// await env.PROCESS_INCOMING_EMAILS_WORKFLOW.create({
// params: {
// message,
// },
// });
}
)
}
./incoming-emails/workflow
export class ProcessIncomingEmailsWorkflow extends WorkflowEntrypoint<
Bindings,
Params
> {}
export class ProcessIncomingEmailsWorkflow extends WorkflowEntrypoint<
Bindings,
Params
> {}
8 Replies
sdr
sdr19h ago
You might be missing the script_name key from your wrangler.toml workflows section [[workflows]] ... script_name = "process-incoming-emails"
telliks
telliksOP19h ago
Is the script_name not just needed when you want to reference a workflow from another worker?
sdr
sdr19h ago
Ah yeah that might be it. I might have an older config. Theres a PR around clarifying that here https://github.com/cloudflare/cloudflare-docs/pull/17770/files
telliks
telliksOP19h ago
Thanks! I'm sure I'm just doing something silly. When you deployed your first worker, did you just add the config to the wrangler.toml file or did you have to create it first with some wrangler cli command and then reference it in the toml file?
sdr
sdr19h ago
Maybe your workflow needs to have its run function defined? export class ProcessIncomingEmailsWorkflow extends WorkflowEntrypoint< Bindings, Params
{
async run(event: WorkflowEvent<Params>, step: WorkflowStep) { const done = await step.do('work', async () => { return true }); return done } } Yeah I just ran it with the cli tool and used the defaults npm create cloudflare@latest workflows-starter -- --template "cloudflare/workflows-starter" Id say try do it from scratch in an independent worker to get it setup first and then migrate what works into your existing hono app
telliks
telliksOP19h ago
Yeah, I think it has something to do with this command: npm create cloudflare@latest workflows-starter -- --template "cloudflare/workflows-starter" AFAIK, that just creates a new worker but uses the given template. Since I already had a worker, I did not run this command and just tried adding the workflow config to my existing worker. Maybe that command does more just scaffold the project structure locally.
sdr
sdr19h ago
I don't think theres any extra scaffolding that it does, theres likely something very small off with your setup but I can't quite spot it
telliks
telliksOP19h ago
Thanks for help checking anyways
Want results from more Discord servers?
Add your server