sim
sim copied to clipboard
feat(schedules): remove save button for schedules, couple schedule deployment with workflow deployment
Summary
- remove save button for schedules, couple schedule deployment with workflow deployment
- added tests
Type of Change
- [x] Bug fix
Testing
Tested manually. Added unit tests
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
Greptile Summary
This PR couples schedule deployment with workflow deployment, removing the separate "Save" button for schedules.
Key Changes:
- Schedules are now automatically created/updated when a workflow is deployed and deleted when undeployed
- Removed the manual schedule save functionality (
ScheduleSavecomponent,use-schedule-managementhook, POST/api/schedules) - Added client-side pre-deploy validation that checks schedule configuration before allowing deployment
- New
ScheduleInfocomponent displays read-only schedule status (next run, last run, failure count) - Simplified
/api/schedules/[id]route to only support reactivation of disabled schedules - Added comprehensive validation functions in
validation.tsfor all schedule types - Added extensive test coverage for the new schedule deploy utilities
Architecture: The change simplifies the schedule lifecycle by eliminating the need for users to manually save schedules. This reduces complexity and ensures schedules are always in sync with deployed workflows.
Confidence Score: 4/5
- This PR is safe to merge with good test coverage and clean architectural changes.
- Well-structured refactoring that simplifies the schedule management system. Comprehensive test coverage added. Minor code quality items noted in previous reviews (unused prop) but no critical issues.
- apps/sim/lib/workflows/schedules/deploy.ts - verify behavior with multiple schedule blocks is as intended
Important Files Changed
| Filename | Overview |
|---|---|
| apps/sim/lib/workflows/schedules/deploy.ts | New file implementing schedule creation/deletion during workflow deployment. Uses upsert pattern with workflowId+blockId conflict target. Minor consideration: generates new UUID on each upsert but existing ID is preserved on conflict. |
| apps/sim/lib/workflows/schedules/validation.ts | New client-safe validation functions for schedule block configuration. Well-structured with proper validation for all schedule types. |
| apps/sim/app/api/workflows/[id]/deploy/route.ts | Modified to validate schedules before deployment and create schedule records during deploy. Deletes schedules within transaction on undeploy. Schedule creation happens outside transaction but with proper error handling. |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks/use-deployment.ts | Enhanced deployment hook with client-side pre-deploy validation. Shows error notifications on validation failure. Clean implementation. |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/schedule-info/schedule-info.tsx | New read-only schedule status component replacing the old schedule-save. Shows cron description, next/last run times, and failure states with redeploy action. |
| apps/sim/app/api/schedules/route.ts | Simplified to GET-only endpoint. POST endpoint removed as schedule creation now happens during deployment. |
| apps/sim/app/api/schedules/[id]/route.ts | Simplified to PUT-only (reactivate action). DELETE removed as schedule deletion now handled during workflow undeploy. |
Sequence Diagram
sequenceDiagram
participant User
participant DeployHook as useDeployment
participant PreDeploy as runPreDeployChecks
participant API as /api/workflows/[id]/deploy
participant Validation as validateWorkflowSchedules
participant Deploy as createSchedulesForDeploy
participant DB as Database
User->>DeployHook: Click Deploy
alt Already Deployed (Redeploy)
DeployHook->>PreDeploy: Validate client-side
PreDeploy->>Validation: Check schedule config
Validation-->>PreDeploy: Result
PreDeploy-->>DeployHook: Pass/Fail
alt Validation Failed
DeployHook-->>User: Show error notification
else Validation Passed
DeployHook-->>User: Open deploy modal
end
else First Deploy
DeployHook->>API: POST /deploy
API->>Validation: validateWorkflowSchedules
Validation-->>API: isValid
alt Invalid Schedule
API-->>DeployHook: 400 Error
DeployHook-->>User: Show error
else Valid
API->>DB: deployWorkflow
API->>Deploy: createSchedulesForDeploy
Deploy->>DB: UPSERT schedule records
Deploy-->>API: ScheduleDeployResult
API-->>DeployHook: Success + schedule info
DeployHook-->>User: Open deploy modal
end
end
@greptile
@greptile
@greptile