forked from amelbakry/kube-schedule-scaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_missed_jobs.py
26 lines (22 loc) · 1.06 KB
/
run_missed_jobs.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
import os
import time
from crontab import CronTab
from datetime import datetime
from datetime import timedelta
scaling_cron = CronTab(user="root")
print("[INFO]", datetime.now(), "Running the Jobs of the last 5 minutes")
for target in ["Deployment", "HPA"]:
scale_jobs = scaling_cron.find_comment("Scheduling_Jobs_" + target)
for job in scale_jobs:
# print(job)
schedule = job.schedule(date_from=datetime.now())
schedule = str(schedule.get_prev())
schedule = time.strptime(schedule, "%Y-%m-%d %H:%M:%S")
retry_execution_threshold = str(datetime.now() - timedelta(minutes=5))
retry_execution_threshold = time.strptime(
retry_execution_threshold, "%Y-%m-%d %H:%M:%S.%f"
)
if schedule > retry_execution_threshold:
# 5 7 * * * . /root/.profile ; /usr/bin/python /root/schedule_scaling/deployment-script.py --namespace ... --deployment ... --replicas 9 2>&1 | tee -a ... # Scheduling_Jobs
schedule_to_execute = str(job).split(";")[1]
os.system(schedule_to_execute)