The Task Scheduler Project is a powerful task scheduling system designed to perform tasks at specific timestamps or recurring intervals. It provides a flexible and user-friendly interface for scheduling and managing tasks, with support for various deployment options.
-
Flask API for CRUD Operations: Manage tasks through a RESTful API, allowing Create, Read, Update, and Delete (CRUD) operations on the task database.
-
Command Line Interface (CLI): Interact with the scheduler through a command-line interface, enabling users to create, update, read, and delete tasks.
-
Parallel Task Execution: Supports parallel execution of tasks, allowing for efficient and concurrent processing.
-
Recurring Task Support: - Users can schedule recurring tasks using cron format via the API, CLI, or Kubernetes Jobs.
-
Kubernetes Deployment: - Easily deploy the scheduler and MySQL database using Helm Charts, simplifying the deployment process.
- Clone the repository:
git clone https://github.com/yrs147/task-schedulers.git
cd repository
- Deploy the scheduler and MySQL with Helm:
helm install myrelease ./project-setup-chart
Field | Type | Constraints |
---|---|---|
id | integer | primary key |
name | varchar | |
execution_time | datetime | |
status | varchar | |
recurring | varchar | |
cron_schedule | varchar |
Timezone inside the container would be in UTC
so schedule your tasks accordingly
Method | Route | Description |
---|---|---|
GET | /api/tasks | Get a list of tasks |
GET | /api/tasks/{taskId} | Get details of a specific task |
POST | /api/tasks | Create a new task |
PUT | /api/tasks/{taskId} | Update details of a specific task |
DELETE | /api/tasks/{taskId} | Delete a specific task |
- Port forward the pod to make the api acessible on
localhost:5000
kubectl port-forward myrelease-taskchart-scheduler 5000:5000
- Now from another terminal window make a request on the respective path
Path - http://localhost:5000/tasks
Request Body(For Recurring Tasks):
{
"id": "1001"
"name": "Task 1001",
"cron_schedule": "*/2 * * * *",
}
id
(integer): The id of the task.name
(string): The name of the task.cron_schedule
(string): The cron schedule for task execution.
Request Body(For Non-Recurring Tasks):
{
"id": "1001"
"name": "Task 1001",
"execution_time": "2024-03-11 00:06:00",
}
id
(integer): The id of the task.name
(string): The name of the task.execution_time
(string): The execution time for non-recurring tasks.
Path - http://localhost:5000/tasks/{task_id}
Request Body(Non Recurring Tasks):
Can update both or either one
{
"name": "Task 1001",
"execution_time": "2024-03-11 00:06:00",
}
Request Body(Recurring Tasks):
Can update both or either one
{
"name": "Task 1001",
"cron_schedule": "* * * * *",
}
GetById and Delete Does not require a request body , just append the task_id at the end of their respective path
Path - http://localhost:5000/tasks/{task_id}
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py create --name TaskName --cron_schedule '*/2 * * * *'
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py create --name TaskName --execution_time '2024-03-11 00:06:00'
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py view
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py get --id="ID"
id
is req to get the task and then you can update either of name
or cron_schedule
or both
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py update --id=1087 --cron_schedule '*/2 * * * *'
id
is req to get the task and then you can update either of name
or execution_time
or both
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py update --id=8765 --name TaskName --execution_time '2024-03-11 00:06:00'
kubectl exec myrelease-taskchart-scheduler -c scheduler -- python ./main.py delete --id=5423
You can also use Kubernetes jobs to create tasks using helm charts or using the manifests in the*crud_jobs
folder
apiVersion: batch/v1
kind: Job
metadata:
name: read-task-job
spec:
template:
spec:
containers:
- name: read-task
image: yrs9480/taskapp:latest
command: ["python", "./main.py", "view"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1
kind: Job
metadata:
name: read-specific-task-job
spec:
template:
spec:
containers:
- name: read-specific-task
image: yrs9480/taskapp:latest
command: ["python", "./main.py", "get", "--id=7465"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1
kind: Job
metadata:
name: create-task-job
spec:
template:
spec:
containers:
- name: create-task
image: yrs9480/taskapp:latest
command: ["python", "./main.py", "create", "--name=NewTask", "--execution_time=2024-03-14 18:55:30"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1
kind: Job
metadata:
name: update-task-job
spec:
template:
spec:
containers:
- name: update-task
image: yrs9480/taskapp:latest
command: ["python", "./main.py", "update", "--id=1", "--name=UpdatedTask"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1
kind: Job
metadata:
name: delete-task-job
spec:
template:
spec:
containers:
- name: delete-task
image: yrs9480/taskapp:latest
command: ["python", "./main.py", "delete", "--id=7647"]
restartPolicy: Never
backoffLimit: 4
helm install create-non-recurring-task-release ./create-non-recurring --set nonRecurringTaskJob.id="ID" --set nonRecurringTaskJob.name="TASK_NAME" --set nonRecurringTaskJob.executionTime="YYYY-MM-DD HH:MM:SS"
helm install create-recurring-task-release ./create-recurring/ --set createTaskJob.id="ID" --set createTaskJob.name="TASK_NAME" --set createTaskJob.cronSchedule="* * * * *"
- Daily:
0 0 * * *
- Weekly:
0 0 * * 0
- Monthly:
0 0 1 * *
- Yearly:
0 0 1 1 *