Scheduler and Tasks
Primary files:
src/task-scheduler.ts- task IPC handling in
src/index.ts(processTaskIpc) - persistence in
src/db.ts
Task Schema
Stored table: scheduled_tasks
Fields:
idgroup_folderchat_jidpromptschedule_type:cron|interval|onceschedule_valuecontext_mode:group|isolatednext_runlast_runlast_resultstatus:active|paused|completedcreated_at
Scheduler Loop
startSchedulerLoop(deps):
- Poll due tasks every
SCHEDULER_POLL_INTERVAL. - Re-fetch each due task by id (skip if paused/cancelled).
- Run task via container agent.
- Log run row into
task_run_logs. - Compute next run:
cron: next CronExpression inTIMEZONEinterval: now + msonce: null (marks completed)
Task Execution Context
runTask(task, deps) resolves target group by group_folder.
If target group missing:
- logs error run
- does not execute
Before each task run:
- updates
current_tasks.jsonsnapshot in group IPC dir.
IPC Task Operations
processTaskIpc(...) supports:
schedule_taskpause_taskresume_taskcancel_taskrefresh_groups(main only)register_group(main only)
Authorization model:
- non-main source group can only schedule/control tasks for itself
- main can control all groups
- task target chat JID is resolved from registered groups, not trusted directly from payload
Schedule Validation Rules
cron: parsed withcron-parser, timezone set toTIMEZONEinterval: integer milliseconds > 0once: valid timestamp parse
Invalid schedule payload is rejected and logged.
User Command Controls (Telegram Main)
Commands:
/tasks/task_pause <id>/task_resume <id>/task_cancel <id>
These call DB mutation helpers directly after task existence checks.