Workflow bindings

Do anyone knows is there any way (or plans) how to integrate Zaraz custom components together with Workflows through bindings (without using the middle Worker)? @Mackenly maybe you know something?
6 Replies
Mackenly
Mackenly2mo ago
You can using Bindings in custom managed components. I haven't personally used it with Workflows though. I don't work for Cloudflare, so I'm limited to just my experience. What's the use case?
m.muiznieks
m.muiznieksOP2mo ago
Yes, I know about the Bindings in general, and I found out that through one of your GH repo examples. I'm using the MC in more than one page and working on custom GA4, FB event processing and want to "remove" that functionality from the MC itself, instead sending and processing the events separately (which includes saving some events on D1 as well). While exploring the Workflows I thought this might be a good use for them. I ask this because I see that MC publishing uses the old 3.29 Wrangler version, which does not recognize the Workflows in wrangler.toml Other way around is using http fetch of course, but..
m.muiznieks
m.muiznieksOP2mo ago
So, I am reading here: https://developers.cloudflare.com/workflows/build/call-workflows-from-pages/#use-service-bindings That Workflows can be triggered and connected as the Service Bindings. I made a template Workflow without any modifications made (so the code is useless here). I'm trying to get it alive as this:
export interface Manager extends OriginalManager {
ext: {
env: {
KV: KVNamespace;
KV2: KVNamespace;
SERVICE_WORKER_THAT_WORKS: {
fetch: (url: string, init: RequestInit) => Promise<Response>;
};
WORKFLOW: Workflow; //Does not work
// WORKFLOW_TEST_2: Service; //Does not work
// WORKFLOW_TEST_3: {
// run: (options?: WorkflowInstanceCreateOptions<unknown> | undefined) => Promise<WorkflowInstance>; //this is named as the actual function in template
// };
// WORKFLOW_TEST_4: {
create: (options?: WorkflowInstanceCreateOptions<unknown> | undefined) => Promise<WorkflowInstance>;
//...
};

};
};
}
export interface Manager extends OriginalManager {
ext: {
env: {
KV: KVNamespace;
KV2: KVNamespace;
SERVICE_WORKER_THAT_WORKS: {
fetch: (url: string, init: RequestInit) => Promise<Response>;
};
WORKFLOW: Workflow; //Does not work
// WORKFLOW_TEST_2: Service; //Does not work
// WORKFLOW_TEST_3: {
// run: (options?: WorkflowInstanceCreateOptions<unknown> | undefined) => Promise<WorkflowInstance>; //this is named as the actual function in template
// };
// WORKFLOW_TEST_4: {
create: (options?: WorkflowInstanceCreateOptions<unknown> | undefined) => Promise<WorkflowInstance>;
//...
};

};
};
}
I tried various ways, up there are few of what I tried. The only thing that works is fetching. What I get is the error:
X [ERROR] TypeError: The RPC receiver does not implement the method "create".
X [ERROR] TypeError: The RPC receiver does not implement the method "create".
This error is for whatever I try (except fetching). Adding a note for this - for the SERVICE_WORKER_THAT_WORKS I have few more methods, that works at other cross-worker bindings, but with zaraz custom managed component I get the same error as above. the Bindings in wrangler.toml
binding = "WORKFLOW"
service = "wf-name-in-cf"
entrypoint = "MyWorkflow"
binding = "WORKFLOW"
service = "wf-name-in-cf"
entrypoint = "MyWorkflow"
I tried with and without entrypoint. Adding the [[workflows]] does not work also, as it throws warning, that it is not recognized and does not appear to bindings.
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.muiznieksOP2mo ago
@yo'av Sorry for disturbing you, but I believe you are one of few who can make some comments about this topic (and I hope you will).
Mackenly
Mackenly2mo ago
Yes, the MC to Worker script needs some dependency updates (see PR, which may itself be outdated at this point). Following to see if you're able to get it to work!
m.muiznieks
m.muiznieksOP2mo ago
For now, I think there is no better way than firing the http post request to the specific workflow. Ok, I still hope for some updates. :/ So far I can tell that Workflows can be connected to Zaraz custom managed component using a standard service worker binding. (await SERVICE_WORKER.fetch(url, options)).body?.cancel(); But I do not recommend waiting for the response from workflow, as in some cases the workflows can set your events to waiting even for 60-80 seconds. Yesterday 'something' went off, and the queue was in terrible length, so the response times from the worker itself. Anyway - I believe [and hope] this will be solved in the future as it is a handy way how to process some of the events (i.e. you might want to see and controle the response from the Facebook API). If there are events that must be processed as soon as possible, do that in the Zaraz component. If the time of the processing does not matter (i.e. the facebook conversions), you can leave them to workflows, because they can be processed even after 40+ minutes (as I've experienced already).

Did you find this page helpful?