-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: workflow delay action (Pause - Wait/Sleep/Delay) #14915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I feel like the |
Sorry I'll close to keep the backlog clean because we have way to many PRs open but let me know when you need more feedback we can re-open any time! |
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:38712 This environment will automatically shut down when the PR is closed or after 5 hours. |
...orkflow/workflow-steps/workflow-actions/delay-actions/components/WorkflowEditActionDelay.tsx
Outdated
Show resolved
Hide resolved
...orkflow/workflow-steps/workflow-actions/delay-actions/components/WorkflowEditActionDelay.tsx
Outdated
Show resolved
Hide resolved
/> | ||
|
||
<WorkflowStepBody> | ||
<Select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop this? Also it's not at a specific date it's the opposite!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I told you to do duration only and I think you did fixed data only 😅. Since we have the wrong one let's go with both then!
case 'FILTER': | ||
case 'EMPTY': | ||
case 'DELAY': | ||
return theme.color.green60; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd? Please refer to Figma or check with @Bonapara
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldnt find a color for filter on Figma. Maybe I might have missed it looking there. I'll push to make sure it uses the same green color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use the green tag color like other nodes from the Flow section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the filter also become green @Bonapara? (also in the flow section)
...erver/src/modules/workflow/workflow-executor/workflow-actions/delay/delay.workflow-action.ts
Outdated
Show resolved
Hide resolved
...ver/src/modules/workflow/workflow-executor/workflow-actions/delay/jobs/delayed-resume.job.ts
Outdated
Show resolved
Hide resolved
const delayInMs = scheduledDate.getTime() - now.getTime(); | ||
|
||
await this.messageQueueService.add<DelayedResumeJobData>( | ||
'DelayedResumeJob', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the queue is full then the delay might not be respected so we might want to do a higher priority queue for those jobs (MessageQueue enum: add workflowDelayedJobsQueue). We don't use priorities right now but a good opportunity to start introducing them. Let's also put the emailQueue in priority / do something clean. lower numbers = higher priority in BullMQ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR implements a comprehensive workflow delay action feature that allows workflows to pause execution either for a specified duration (days, hours, minutes, seconds) or until a specific scheduled date/time. The implementation spans both frontend and backend systems, creating a complete end-to-end solution.On the backend, the change introduces a new DELAY
workflow action type with dedicated schemas, types, and execution logic. The DelayWorkflowAction
calculates delay timing and schedules resume jobs through a message queue system, while ResumeDelayedJob
handles resuming workflow execution after delays expire. A new priority-based message queue system ensures delayed jobs receive highest priority (priority 1) for timely execution.
The frontend provides a dual-mode configuration interface through WorkflowEditActionDelay
component, allowing users to choose between scheduled datetime delays or duration-based delays. The component includes proper form validation, debounced saving, and readonly support for completed workflows. Visual integration includes appropriate icons (pause symbol), color theming (green), and localization support.
The architecture follows established patterns in the codebase with proper type safety, error handling, and integration with existing workflow systems. The delay action is properly registered in the workflow factory, integrated into workflow execution modules, and added to all relevant UI components for comprehensive support across the workflow system.
Important Files Changed
Changed Files
Filename | Score | Overview |
---|---|---|
packages/twenty-server/src/engine/core-modules/message-queue/message-queue.constants.ts |
2/5 | Added workflowDelayedJobsQueue constant but with queue mismatch issue |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/jobs/resume-delayed.job.ts |
4/5 | New job handler for resuming delayed workflows with proper error handling |
packages/twenty-server/src/engine/core-modules/message-queue/message-queue-priority.constant.ts |
4/5 | New priority system with workflow delays getting highest priority |
packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/delay-actions/components/WorkflowEditActionDelay.tsx |
4/5 | Main delay action configuration component with dual delay modes |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/delay.workflow-action.ts |
4/5 | Core delay action implementation with message queue scheduling |
packages/twenty-shared/src/workflow/schemas/workflow-delay-action-settings-schema.ts |
4/5 | Zod schema for delay action settings validation |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/types/workflow-delay-action-input.type.ts |
4/5 | TypeScript types for delay action input configuration |
packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepNodeDetail.tsx |
4/5 | Added readonly delay action support in workflow run view |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/guards/is-workflow-delay-action.guard.ts |
4/5 | Type guard for delay actions with consistent patterns |
packages/twenty-server/src/engine/core-modules/message-queue/drivers/bullmq.driver.ts |
4/5 | Added delay and priority support to message queue driver |
packages/twenty-shared/src/workflow/index.ts |
5/5 | Export statements for delay action schemas |
packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIcon.ts |
5/5 | Added pause icon for delay actions |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/types/workflow-delay-action-settings.type.ts |
5/5 | Type definition following established patterns |
packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionHeaderTypeOrThrow.ts |
5/5 | Added internationalized delay action header |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts |
5/5 | Core delay action type integration with workflow system |
packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow.ts |
5/5 | Green color assignment for delay actions |
packages/twenty-shared/src/workflow/schemas/workflow-delay-action-schema.ts |
5/5 | Base delay action schema following established patterns |
packages/twenty-server/src/engine/core-modules/message-queue/drivers/interfaces/job-options.interface.ts |
5/5 | Added delay property to job options interface |
packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service.ts |
5/5 | Default delay step configuration with consistent patterns |
packages/twenty-front/src/modules/workflow/types/Workflow.ts |
5/5 | Frontend type integration following Zod schema patterns |
packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepDetail.tsx |
5/5 | Added delay action case to workflow step detail component |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/delay-action.module.ts |
5/5 | Module definition following established action module patterns |
packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/constants/FlowActions.ts |
5/5 | Added delay to flow actions with proper icon and label |
packages/twenty-front/src/modules/workflow/workflow-diagram/workflow-nodes/components/WorkflowDiagramStepNodeIcon.tsx |
5/5 | Visual integration with green color theming |
packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts |
5/5 | Factory registration for delay actions |
packages/twenty-shared/src/workflow/schemas/workflow-action-schema.ts |
5/5 | Integration into main workflow action discriminated union |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts |
5/5 | Module registration in workflow executor |
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type.ts |
5/5 | Union type extension for delay action settings |
Confidence score: 3/5
- This PR introduces a complex delay action system with proper backend job scheduling and frontend UI, but has a critical queue mismatch issue that could prevent delayed jobs from being processed
- Score lowered due to the inconsistency between DelayWorkflowAction using
workflowDelayedJobsQueue
while ResumeDelayedJob processor listens toworkflowQueue
, which could result in jobs being queued but never processed - Pay close attention to message queue configuration files to ensure DelayWorkflowAction and ResumeDelayedJob use the same queue for proper job processing
Sequence Diagram
sequenceDiagram
participant User
participant Frontend
participant WorkflowExecutor
participant DelayWorkflowAction
participant MessageQueue
participant ResumeDelayedJob
participant WorkflowRunner
User->>Frontend: "Configure delay action"
Frontend->>Frontend: "Set delay type (schedule_date/duration)"
Frontend->>Frontend: "Configure delay parameters"
Note over User,WorkflowRunner: Workflow Execution starts
WorkflowExecutor->>DelayWorkflowAction: "execute(stepId, settings, runInfo)"
DelayWorkflowAction->>DelayWorkflowAction: "Validate delay action type"
alt Scheduled Date
DelayWorkflowAction->>DelayWorkflowAction: "Calculate delay from scheduledDateTime"
DelayWorkflowAction->>DelayWorkflowAction: "delayInMs = scheduledDate - now"
else Duration
DelayWorkflowAction->>DelayWorkflowAction: "Calculate delay from duration"
DelayWorkflowAction->>DelayWorkflowAction: "delayInMs = days*24*60*60*1000 + hours*60*60*1000 + minutes*60*1000 + seconds*1000"
end
DelayWorkflowAction->>MessageQueue: "add('ResumeDelayedJob', jobData, { delay: delayInMs })"
DelayWorkflowAction-->>WorkflowExecutor: "{ pendingEvent: true }"
Note over MessageQueue: Delay period passes
MessageQueue->>ResumeDelayedJob: "handle({ workspaceId, workflowRunId, stepId })"
ResumeDelayedJob->>ResumeDelayedJob: "Get workflow run status"
alt Workflow still running
ResumeDelayedJob->>MessageQueue: "add('RunWorkflowJob', runData)"
ResumeDelayedJob->>WorkflowRunner: "increaseWorkflowRunQueuedCount()"
MessageQueue->>WorkflowRunner: "Continue workflow execution"
else Workflow not running
ResumeDelayedJob->>ResumeDelayedJob: "Skip execution"
end
Additional Comments (3)
-
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/types/workflow-delay-action-input.type.ts
, line 3 (link)style: Consider using a more specific type than
string
for scheduledDateTime, such as ISO 8601 datetime string or a branded type for better type safety -
packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/delay/types/workflow-delay-action-input.type.ts
, line 1-10 (link)logic: The type structure should enforce mutual exclusivity - when delayType is 'schedule_date', only scheduledDateTime should be required, and when 'duration', only duration should be required
-
packages/twenty-shared/src/workflow/schemas/workflow-delay-action-settings-schema.ts
, line 8 (link)style: Consider using ISO 8601 datetime format validation instead of just string() for scheduledDateTime
Context used:
Rule from dashboard
- Use lingui for all user-facing strings to make them translatable, including field type labels and UI... (source)
28 files reviewed, 8 comments
Description
Visual Appearance