Imagine that we want the written code to be executed once or periodically at a certain time. Apscheduler is just the library for the Python language that will enable us to do this.
What is Apscheduler?
Apscheduler is an open source library for the Python language. Apscheduler allows us to schedule later execution of code, either once or periodically. Apscheduler allows us to add or remove tasks "on the fly". There is no limit to the number of tasks Apscheduler can schedule. The number of tasks depends only on the server load. By default, Apscheduler stores all tasks in memory. If you want the tasks to survive after a restart, we can store these tasks in any database. Apscheduler offers us three basic scheduling systems:
- Scheduling with optional start and end times
- Execution of plans based on intervals
- One-time delayed execution of a task at a specific date and time
The main components in the Apscheduler library
There are 4 main components that make up the Python APScheduler library, and these are:
- Triggers - these are responsible for scheduling logic and deciding when a task should be executed.
- Task store - as the name suggests, it defines the area where all scheduled tasks are stored.
- Contractors - are in charge of executing tasks.
- Schedulers - the backbone that ties everything together. Usually there is only one scheduler per application.