Skip to main content

Task Management

ADMIN DEVELOPER

EZ-Console includes a task subsystem: background work with progress, cancellation, retries, optional artifacts, execution logs, and cron schedules. This page mirrors the framework usages task guide for operators and module authors.

User-facing UI​

AreaPathPermission
Task list/taskstask:list
Task detail/tasks/:idtask:view
Scheduled tasks/tasks/schedulestask:schedule:list (toggle/trigger need task:schedule:update)
Header dropdown(layout header)task:list
  • Visibility: Non-admins see only tasks they created; admins see all.
  • Polling: Detail page polls while status is pending or running; header dropdown uses GET /api/user-tasks (recent user-category tasks) with faster polling while open.
  • Artifacts: Download via GET /api/files/:fileKey when artifact_file_key is set.

System settings​

System Settings β†’ Task Settings (requires system:settings:view / system:settings:update):

Setting keyPurpose
task_max_concurrentWorker concurrency (default 10)
task_log_storage_backendWhere execution logs are stored (default database); options from GET /api/system/task-settings/log-storage-backends

Runners should log with log.GetContextLogger(ctx) so lines are captured into the configured backend.

Permissions (summary)​

CodeTypical use
task:list / task:viewList and inspect
task:cancel / task:retry / task:deleteLifecycle actions
task:schedule:list / task:schedule:updateCron UI

HTTP APIs (selection)​

MethodPathNotes
GET/api/tasksPaginated list; current, page_size, search
GET/api/tasks/:idDetail
GET/api/tasks/:id/logsExecution logs
POST/api/tasks/:id/cancelCancel
POST/api/tasks/:id/retryRetry
DELETE/api/tasks/:idSoft delete
GET/api/user-tasksHeader dropdown (auth only)
GET/api/task-schedulesCron definitions
POST/api/task-schedules/:id/toggleEnable/disable
POST/api/task-schedules/:id/triggerRun once

There is no generic HTTP create for tasks: modules call TaskService.CreateTask from handlers and return the task row to the client.

For developers: create a task​

task, err := svc.TaskService.CreateTask(ctx, "export",
service.WithPayload(`{"scope":"users"}`),
service.WithMaxRetries(2),
)

Options include WithCategory (user vs system), WithCronScheduleID, etc. Creator comes from the authenticated user on ctx when present.

Example pattern (user export in the main repo): POST /api/authorization/users/export β†’ CreateTask with type user_export β†’ frontend calls addTask from SiteContext so the header dropdown opens. Reuse this pattern for long-running jobs.

Registering task types​

Use pkg/taskscheduler:

taskscheduler.RegisterTaskType("export", &ExportRunner{})
// or
taskscheduler.RegisterFuncTaskType("cleanup", func(ctx context.Context, t *model.Task, progressCallback taskscheduler.ProgressCallback, cancelCh <-chan struct{}) (interface{}, error) {
// ...
return nil, nil
})

Respect cancelCh; return taskscheduler.ErrCancelled when cancelled. Report progress with progressCallback. Associate artifacts with TaskService.SetTaskArtifact when producing files.

Scheduled (cron) jobs​

Register in code with taskscheduler.RegisterScheduledJob (ScheduledJobDef: id, name, cron Spec, task type, payload builder, optional Runner). Definitions are in-memory, not migrated from SQL; changing jobs requires a deploy. When a schedule fires, TaskService.CreateTask runs with category system and the schedule id.

Observability​

Counters and gauges such as task_created_total, task_queue_overflow_total, task_queue_length, and task_run_duration_seconds are documented in the framework task guideβ€”useful when tasks stay pending (queue full, missing runner, etc.).


Need help? Ask in GitHub Discussions.