The system is web-based, so all APIs should be authenticated against JWT.
POST /task
req: {
dedup_id,
schedule: (cron format, task is one time if left empty),
delay: (11 timestamp - how long to wait until running),
docker_image_name
docker_image_tag
priority
}
resp: {
task_id
}
PUT /task
req: {
task_id,
schedule: (cron format, task is one time if left empty),
delay: (11 timestamp - how long to wait until running),
docker_image_name
docker_image_tag
priority
}
PUT /task/status
req: {
status: enable/disable
}
DELETE /task?id=...
GET /task?id=...
resp: one task detail, and running status, schedule history
{
task_id
detail: {...}
status: (created/to be scheduled/running/finished),
history: [ {
scheduled_timestamp, status (success/failed)
} ]
}
GET /tasks
resp: task list
Data model:
UserTask
id(pk), user_id(fk), dedup_key(uk), docker_image_name, docker_image_tag, delay, priority, cron, status, task_state, created_time, updated_time
SchedulerTask
task_id, execution_id, user_id, timestamp, state
User(id, name, etc.)
State Transition:
created -> waiting/waiting_for_resource -> running -> success/failed/no_resource
On a high-level the system takes a task and stores it in the database, and sends a message to a scheduler.
A backend scheduler sorts all the enabled tasks based on priority in Redis and creates scheduler tasks, executes them, then updates the status based on execution result, send them back to the MQ to notify the Task service.
Task Service:
Scheduler:
Recurring Task Handling:
In the Redis task list, it is the user task. For each recurring user task, the scheduler would monitor its time, when it matches the current time, create a scheduler task for it with an execution_id, and send it to the MQ for the executor to subscribe.
Dedup:
The dedup key is generated by the web-end, since the dedup field is a uk in the database, the Task Service would be able to prevent double-creating the task.
HA Design:
Scalability:
One critical point is the task resource on k8s. We can do the following:
Another is the scheduler partitioning: