The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update scheduled workflow triggers.
Kiran Kf7bdda8d497b
diff --git a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts b/apps/web/lib/api/workflows/execute-send-campaign-workflow.tsindex cfd6226a06..54fb5e42bb 100644--- a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts+++ b/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts@@ -67,8 +67,11 @@ export const executeSendCampaignWorkflow = async ({condition,});+ console.log(+ `Found ${programEnrollments.length} program enrollments to send campaign emails to.`,+ );+if (programEnrollments.length === 0) {- console.log(`Found no program enrollments for campaign ${campaignId}.`);return;}@@ -282,6 +285,7 @@ async function getProgramEnrollments({return [programEnrollment];}+ // We need to get all program enrollments that match the condition for the scheduled workflowsreturn await prisma.programEnrollment.findMany({where: {programId,diff --git a/apps/web/lib/api/workflows/utils.ts b/apps/web/lib/api/workflows/utils.tsindex 202aa09549..9eaa7a9703 100644--- a/apps/web/lib/api/workflows/utils.ts+++ b/apps/web/lib/api/workflows/utils.ts@@ -1,4 +1,5 @@import { WorkflowConditionAttribute } from "@/lib/types";+import { SCHEDULED_WORKFLOW_TRIGGERS } from "@/lib/zod/schemas/workflows";import { Workflow } from "@dub/prisma/client";import { parseWorkflowConfig } from "./parse-workflow-config";@@ -9,13 +10,11 @@ export const isDaysAttribute = (activity: WorkflowConditionAttribute) =>activity === "partnerEnrolledDays";export const isScheduledWorkflow = (workflow: Workflow) => {- const workflowAttributes: WorkflowConditionAttribute[] = [- "partnerEnrolledDays",- "totalClicks",- "totalCommissions",- ];-const { condition } = parseWorkflowConfig(workflow);- return workflowAttributes.includes(condition.attribute);+ if (condition.attribute === "partnerJoined") {+ return false;+ }++ return SCHEDULED_WORKFLOW_TRIGGERS.includes(workflow.trigger);};diff --git a/apps/web/lib/zod/schemas/workflows.ts b/apps/web/lib/zod/schemas/workflows.tsindex 55d15cd4c9..9be06203e4 100644--- a/apps/web/lib/zod/schemas/workflows.ts+++ b/apps/web/lib/zod/schemas/workflows.ts@@ -47,8 +47,15 @@ export const WORKFLOW_ATTRIBUTE_TRIGGER: Record<export const WORKFLOW_COMPARISON_OPERATORS = ["gte"] as const;+export const SCHEDULED_WORKFLOW_TRIGGERS: WorkflowTrigger[] = [+ "clickRecorded",+ "commissionEarned",+ "partnerEnrolled",+];+export const WORKFLOW_SCHEDULES: Partial<Record<WorkflowTrigger, string>> = {clickRecorded: "*/5 * * * *", // every 5 minutes+ commissionEarned: "*/5 * * * *", // every 5 minutespartnerEnrolled: "0 */12 * * *", // every 12 hours};