-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
30 lines (23 loc) · 936 Bytes
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from apscheduler.executors.pool import ThreadPoolExecutor
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.schedulers.background import BackgroundScheduler
from utils import Singleton
class Scheduler(metaclass=Singleton):
def __init__(self) -> None:
self.jobstores = {
"default": MemoryJobStore(),
}
self.executors = {"default": ThreadPoolExecutor(100)}
self.scheduler = BackgroundScheduler(
jobstores=self.jobstores, executors=self.executors
)
self.start()
def start(self):
self.scheduler.start()
def shutdown(self):
self.scheduler.shutdown()
def add_jobstore(self, jobstore, alias, **kwargs):
self.jobstores.update({alias: jobstore})
self.scheduler.add_jobstore(jobstore, alias=alias, **kwargs)
def add_job(self, *args, **kwargs):
self.scheduler.add_job(*args, **kwargs)