Add detailed documentation for recurring tasks, including a user guide explaining how to set up and manage recurring tasks, and a technical guide for the recurring tasks cron job. The user guide covers the purpose, setup process, and schedule options, while the technical guide explains the cron job's logic, database interactions, and configuration options. Additionally, include a migration script to fix ENUM type and casting issues for progress_mode_type.
2.9 KiB
2.9 KiB
Recurring Tasks Cron Job Documentation
Overview
The recurring tasks cron job automates the creation of tasks based on predefined templates and schedules. It ensures that tasks are generated at the correct intervals without manual intervention, supporting efficient project management and timely task assignment.
Purpose
- Automatically create tasks according to recurring schedules defined in the database.
- Prevent duplicate task creation for the same schedule and date.
- Assign team members and labels to newly created tasks as specified in the template.
Scheduling Logic
- The cron job is scheduled using the cron package.
- The schedule is defined by a cron expression (e.g.,
*/2 * * * *for every 2 minutes, or0 11 */1 * 1-5for 11:00 UTC on weekdays). - On each tick, the job:
- Fetches all recurring task templates and their schedules.
- Determines the next occurrence for each template using
calculateNextEndDate. - Checks if a task for the next occurrence already exists.
- Creates a new task if it does not exist and the next occurrence is within the allowed future window.
Database Interactions
- Templates and Schedules:
- Templates are stored in
task_recurring_templates. - Schedules are stored in
task_recurring_schedules. - The job joins these tables to get all necessary data for task creation.
- Templates are stored in
- Task Creation:
- Uses a stored procedure
create_quick_taskto insert new tasks. - Assigns team members and labels by calling appropriate functions/controllers.
- Uses a stored procedure
- State Tracking:
- Updates
last_checked_atandlast_created_task_end_datein the schedule after processing.
- Updates
Task Creation Process
- Fetch Templates: Retrieve all templates and their associated schedules.
- Determine Next Occurrence: Use the last task's end date or the schedule's creation date to calculate the next due date.
- Check for Existing Task: Ensure no duplicate task is created for the same schedule and date.
- Create Task:
- Insert the new task using the template's data.
- Assign team members and labels as specified.
- Update Schedule: Record the last checked and created dates for accurate future runs.
Configuration & Extension Points
- Cron Expression: Modify the
TIMEconstant in the code to change the schedule. - Task Template Structure: Extend the template or schedule interfaces to support additional fields.
- Task Creation Logic: Customize the task creation process or add new assignment/labeling logic as needed.
Error Handling
- Errors are logged using the
log_errorutility. - The job continues processing other templates even if one fails.
References
- Source:
src/cron_jobs/recurring-tasks.ts - Utilities:
src/shared/utils.ts - Database:
src/config/db.ts - Controllers:
src/controllers/tasks-controller.ts
For further customization or troubleshooting, refer to the source code and update the documentation as needed.