[PR #24428] feat: add workflow schedule trigger support #30631

Closed
opened 2026-02-21 20:47:55 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/24428

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

part of #23981
close #24021

This PR implements workflow schedule trigger support for Dify, enabling users to execute workflows automatically based on cron expressions with timezone support.

Features Implemented

1. Schedule Trigger Node

  • New trigger node type trigger-schedule for workflow configuration
  • Support for standard cron expressions (e.g., 0 9 * * 1-5 for weekdays at 9 AM)
  • Passes current time as input to triggered workflows

2. Custom Celery Beat Scheduler

  • Database-driven dynamic scheduler replacing default Beat scheduler
  • High availability support using PostgreSQL's SELECT FOR UPDATE SKIP LOCKED
  • Configurable tick intervals and batch processing

3. Automatic Schedule Management

  • Schedules plan automatically created/updated when publishing workflows
  • Schedules plan delete when workflow has no schedule trigger node
  • One-to-one mapping between app and schedule plan

4. Performance Optimizations

  • Batch database updates to reduce round trips

How to Test

1. Migrate database

 uv run flask db upgrade

2. Setup Schedule Trigger in Workflow:

  • Create a new workflow
  • Add a "Schedule Trigger" node as the start node
  • Configure cron expression
  • Add workflow logic after the trigger
  • Publish the workflow

3. Start the Scheduler Service:

# Start celery worker
dev/start-worker

# Start celery beat
dev/start-beat

3. Verify Execution:

  • Check workflow run history in the UI

TODO

Schedule Trigger

  • Use UUIDv7 as PK for workflow_schedule_plans table
  • Use beat_schedule instead of Custom Scheduler
  • Adjust workflow_schedule_plans table structure
  • Stop dispatching tasks when the daily limit is reached
  • Add a check when exporting DSL files
  • Add a failure log when the daily limit is reached

Test

  • Unit Tests
  • Integration Tests

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/24428 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> part of #23981 close #24021 This PR implements workflow schedule trigger support for Dify, enabling users to execute workflows automatically based on cron expressions with timezone support. ### Features Implemented **1. Schedule Trigger Node** - New trigger node type trigger-schedule for workflow configuration - Support for standard cron expressions (e.g., 0 9 * * 1-5 for weekdays at 9 AM) - Passes current time as input to triggered workflows **2. Custom Celery Beat Scheduler** - Database-driven dynamic scheduler replacing default Beat scheduler - High availability support using PostgreSQL's `SELECT FOR UPDATE SKIP LOCKED` - Configurable tick intervals and batch processing **3. Automatic Schedule Management** - Schedules plan automatically created/updated when publishing workflows - Schedules plan delete when workflow has no schedule trigger node - One-to-one mapping between app and schedule plan **4. Performance Optimizations** - Batch database updates to reduce round trips ### How to Test **1. Migrate database** ```bash uv run flask db upgrade ``` **2. Setup Schedule Trigger in Workflow:** - Create a new workflow - Add a "Schedule Trigger" node as the start node - Configure cron expression - Add workflow logic after the trigger - Publish the workflow **3. Start the Scheduler Service:** ```bash # Start celery worker dev/start-worker # Start celery beat dev/start-beat ``` **3. Verify Execution:** - Check workflow run history in the UI ### TODO #### Schedule Trigger - [x] Use [UUIDv7](https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7) as PK for workflow_schedule_plans table - [x] Use beat_schedule instead of Custom Scheduler - [x] Adjust `workflow_schedule_plans` table structure - [x] Stop dispatching tasks when the daily limit is reached - [ ] Add a check when exporting DSL files - [ ] Add a failure log when the daily limit is reached #### Test - [x] Unit Tests - [ ] Integration Tests ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:47:55 -05:00
yindo closed this issue 2026-02-21 20:47:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30631