-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
32 lines (24 loc) · 1.12 KB
/
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
31
32
import apscheduler.job
import pytz
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.schedulers.background import BackgroundScheduler
from config import settings
from tracking_service import tracking_task
scheduler = BackgroundScheduler()
def configure_and_start_scheduler() -> apscheduler.job.Job:
if not scheduler.running:
jobstores = {"default": RedisJobStore(host=settings.REDIS_HOSTNAME,
port=settings.REDIS_PORT,
password=settings.REDIS_PASSWORD)}
scheduler.configure(
jobstores=jobstores, timezone=pytz.timezone("Europe/Warsaw")
)
scheduler.start()
tracking_job = scheduler.add_job(tracking_task,
'interval',
seconds=30,
# minutes=1,
id='tracking_job',
max_instances=1,
replace_existing=True)
return tracking_job