is `npx wrangler types` supposed to work

is npx wrangler types supposed to work for workflows? wrangler.toml: services = [{ binding = "WORKFLOW_PROCESS_TRANSACTIONS", service = "money" }] wrangler version: wrangler 3.107.3 generated interface, WORKFLOW_PROCESS_TRANSACTIONS should be Workflow?
interface Env {
SESSION_SECRET: string;
DB: D1Database;
WORKFLOW_PROCESS_TRANSACTIONS: Fetcher;
}
interface Env {
SESSION_SECRET: string;
DB: D1Database;
WORKFLOW_PROCESS_TRANSACTIONS: Fetcher;
}
15 Replies
will smith
will smithOP3w ago
It feels like the guides are super targeted at going from scratch. I'm adding them into my remix app on pages
will smith
will smithOP3w ago
It's also highly possible I'm doing it wrong, trying to follow this: https://developers.cloudflare.com/workflows/build/call-workflows-from-pages/
Cloudflare Docs
Call Workflows from Pages · Cloudflare Workflows docs
You can bind and trigger Workflows from Pages Functions by deploying a Workers project with your Workflow definition and then invoking that Worker using service bindings or a standard fetch() call.
m.muiznieks
m.muiznieks3w ago
1. Deploy another worker. 2. Add custom domain to it (i.e. worker.yourdomain.com) 3. Implement workflow classes, logic, etc at this worker. 4. Add binding similar as you do, 5. call it as env.WORKFLOW_PROCESS_TRANSACTIONS.fetch(url, options) This is exactly how I make cross-worker connections and it should work from the pages as well.
No description
m.muiznieks
m.muiznieks3w ago
After nr. 4 don't forget npx wrangler types
Matt Silverlock
Better: https://developers.cloudflare.com/workflows/build/workers-api/#cross-script-calls you can call across to it as a Workflow. No need to fetch
{
"name": "web-api-worker",
"main": "src/index.ts",
"compatibility_date": "2024-10-22",
"workflows": [
{
"name": "billing-workflow",
"binding": "MY_WORKFLOW",
"class_name": "MyWorkflow",
"script_name": "billing-worker"
}
]
}
{
"name": "web-api-worker",
"main": "src/index.ts",
"compatibility_date": "2024-10-22",
"workflows": [
{
"name": "billing-workflow",
"binding": "MY_WORKFLOW",
"class_name": "MyWorkflow",
"script_name": "billing-worker"
}
]
}
m.muiznieks
m.muiznieks3w ago
Maybe. I just took this approach from the Zaraz, as it does not support the workflows directly (as its based on wranglers 3.19 or something version).
will smith
will smithOP2w ago
thanks for the help. @Matt I'm not looking to put it in a different worker, I want access to all the same stuff in my server (db, email-sending, types etc.). How can I keep the workflow in the same service?
Matt Silverlock
If you're using Pages, it must be in a separate service. If you're using Workers... follow the tutorial. The default is part of the same Worker.
will smith
will smithOP2w ago
Ah ok. Can I bank on using 1 service in the future with the converging of workers and pages? Should I be getting off pages altogether eventually?
Matt Silverlock
It will converge on Workers (+ Static Assets) - so if you deploy that way it will just work. The Pages binding is fairly straightforward though + you don’t need to “maintain” it.
will smith
will smithOP2w ago
The Pages binding is fairly straightforward though + you don’t need to “maintain” it.
To make sure I'm not misunderstanding, this is deploying the separate workers service with your workflow and calling it from pages right? Not solving the problem I mentioned where all my backend code is already in my pages app? Want to make sure I'm not missing something
Matt Silverlock
Correct. Workflow = Workers. Keep your Pages app as-is. We aren't forcing you to migrate/move off Pages. You can choose to adopt Workers + Static Assets if you want it to be a monorepo.
will smith
will smithOP7d ago
Fair enough. Just my feedback as a user, it doesn't seem like I should keep on pages long-term. I was already missing out on cron triggers, and now this. Calling a separate app (duplicating my backend setup into a different worker) is a non-starter for my projects. I'm not saying Cloudflare is forcing me to migrate off, but if I want the new goodies, it sounds like I should.
Matt Silverlock
I don’t see how you would need to duplicate the setup?
will smith
will smithOP2d ago
If you're using Pages, it must be in a separate service.
My workflow must be in a separate service right? So to do anything server-related don't I need the same server-related stuff that's already in my pages app? e.g. DB credentials, email template, types. To be clear, today I have a remix pages app. What I'm understanding is I can't add workflows to my service, so the recommendation is deploy a separate service with the workflow and call that from my existing service.

Did you find this page helpful?