MCPcopy
hub / github.com/dubinc/dub / executeWorkflows

Function executeWorkflows

apps/web/lib/api/workflows/execute-workflows.ts:43–214  ·  view source on GitHub ↗
({
  trigger,
  reason,
  identity,
  metrics,
}: WorkflowContext)

Source from the content-addressed store, hash-verified

41};
42
43export async function executeWorkflows({
44 trigger,
45 reason,
46 identity,
47 metrics,
48}: WorkflowContext) {
49 const { programId, partnerId } = identity;
50
51 let workflows = await prisma.workflow.findMany({
52 where: {
53 programId,
54 disabledAt: null,
55 trigger,
56 },
57 });
58
59 if (workflows.length === 0) {
60 console.log(
61 `No workflows found to execute for trigger ${trigger} and reason ${reason}.`,
62 );
63 return;
64 }
65
66 // Parse all workflow configs once upfront, filtering out any that fail to parse
67 const parsedWorkflows = workflows
68 .map((workflow) => {
69 try {
70 return {
71 workflow,
72 config: parseWorkflowConfig(workflow),
73 };
74 } catch (error) {
75 console.error(
76 `Failed to parse workflow config for workflow ${workflow.id}, skipping:`,
77 error,
78 );
79 return null;
80 }
81 })
82 .filter(
83 (
84 item,
85 ): item is {
86 workflow: Workflow;
87 config: ReturnType<typeof parseWorkflowConfig>;
88 } => item !== null,
89 );
90
91 if (parsedWorkflows.length === 0) {
92 console.log(
93 `No valid workflows found to execute for trigger ${trigger} and reason ${reason}.`,
94 );
95 return;
96 }
97
98 // Filter by reason if provided
99 let filteredWorkflows = parsedWorkflows;
100 if (reason) {

Callers 14

executeSideEffectsFunction · 0.90
trackLeadFunction · 0.90
_trackLeadFunction · 0.90
_trackSaleFunction · 0.90
attributeViaDiscountCodeFunction · 0.90
createShopifySaleFunction · 0.90
route.tsFile · 0.90
stepRunSideEffectsFunction · 0.90
checkoutSessionCompletedFunction · 0.90
invoicePaidFunction · 0.90
createNewCustomerFunction · 0.90

Calls 3

parseWorkflowConfigFunction · 0.90
executeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…