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),
payload: (an executable, multipart binary)
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),
payload: (an executable, multipart binary)
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), payoad_s3_path, 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 memory and creates scheduler tasks, executes them, then update the status based on execution result, send them back to the MQ to notify the Task service.
Task Service:
Scheduler:
HA Design:
Scalability:
One critical point is the task resource on k8s. We can do the following: