Background: I used to integrate timed tasks in an automated test platform, and it took a long time to solve the problem of repeated execution based on the APScheduler library. Integrating timed tasks in a service also made the service complex. In the end, we chose a timed task service developed in go language by another team in the company. So the idea was born to implement a generic timed task service with Python. Thus, schedule-server was born.
GitHub Address./SeldomQA/schedule-server
schedule-server Features
- Simple to run and deploy.
- HTTP-based trigger request.
- Three types of timed tasks are supported:
crontab
、interval
、date
- timed tasks
consult (a document etc)
、removing
、increase
、Pause/resume
and other operations.
schedule-server architecture
-
schedule_server
: The core function is to trigger HTTP requests at regular intervals. -
fontend
: Manage timed tasks through the front-end UI. -
you server
: Manage timed tasks in your service by calling the interface. -
SQLite
: Used to save the timed task service. -
Redis
: Resolve repeat triggers with Redis locks.
Installation and operation
Installation of dependencies
> cd schedule_server
> pip install -r
development and operation
> uvicorn main:app --reload
INFO: Will watch for changes in these directories: ['/.../schedule-server/schedule_server']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [21905] using StatReload
INFO: Started server process [21907]
INFO: Waiting for application startup.
View API
Access URL.http://127.0.0.1:8000/docs
front-end service
You can use the schedule_server service without a front-end, but you want a visual way to manage timed tasks, and I've developed a front-end service specifically for that purpose.
Installation of dependencies
> npm install
Operational services
> npm run dev
> [email protected] dev
> vite
VITE v4.3.9 ready in 3426 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
Access to front-end pages
Visit url.http://localhost:5173/
Timing type
schedule-server supports three timing types:crontab
、interval
、date
The company can meet different needs.
date type
The data type is simpler and suitable for fixedDate Time
Trigger a timed task.
-
invoke an interface
- URL:http://127.0.0.1:8000/scheduler/date/add_job
- Method:
POST
- Type:
JSON
{
"job_id": "date_job_111",
"url": "/get?id=111",
"year": 2022,
"month": 11,
"day": 18,
"hour": 7,
"minute": 0,
"second": 0
}
- Front-end configuration
Interval type
interval is suitable for intervalsrepeatable
of timed tasks.
-
invoke an interface
- URL:http://127.0.0.1:8000/scheduler/interval/add_job
- Method:
POST
- Type:
JSON
{
"job_id": "interval_job_222",
"url": "/get?id=222",
"hours": 0,
"minutes": 0,
"seconds": 10
}
- Front-end configuration
cron type
conn makes a complex timed task that can support all timed task requirements.
-
invoke an interface
- URL:http://127.0.0.1:8000/scheduler/cron/add_job
- Method:
POST
- Type:
JSON
{
"job_id": "cron_job_333",
"url": "/get?id=333",
"second": "0",
"minute": "*/3",
"hour": "*",
"day": "*",
"month": "*",
"day_of_week": "*"
}
You can refer to this website to learn:/crontab-parse/
- Front-end configuration