Scheduler working
This commit is contained in:
parent
2b18e02623
commit
fa8b511ef4
@ -15,6 +15,7 @@ from bot import bot
|
|||||||
import sys
|
import sys
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||||
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from api_handling.api_handler import API_Handler
|
from api_handling.api_handler import API_Handler
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ def update_crontab(pCurrent_Time, p_my_handler):
|
|||||||
global user_crontab
|
global user_crontab
|
||||||
global user_ids
|
global user_ids
|
||||||
|
|
||||||
p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "8 17 * * *")
|
#p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "23 08 * * *")
|
||||||
|
|
||||||
all_users = p_my_handler.get_all_users()
|
all_users = p_my_handler.get_all_users()
|
||||||
|
|
||||||
@ -76,45 +77,31 @@ def update_crontab(pCurrent_Time, p_my_handler):
|
|||||||
user_crontab.append(str(element["cron"]))
|
user_crontab.append(str(element["cron"]))
|
||||||
|
|
||||||
print(user_ids)
|
print(user_ids)
|
||||||
update_based_on_crontab(user_ids, user_crontab)
|
|
||||||
|
|
||||||
p1 = Process(target= sleeping_time, args=(pCurrent_Time, ))
|
update_based_on_crontab(user_ids, user_crontab, p_my_handler)
|
||||||
p1.start()
|
|
||||||
p3 = Process(target= update_based_on_crontab, args=(user_ids, user_crontab ) )
|
|
||||||
p3.daemon = True
|
|
||||||
p3.start()
|
|
||||||
p1.join()
|
|
||||||
p3.terminate()
|
|
||||||
p1.terminate()
|
|
||||||
|
|
||||||
update_crontab(datetime.datetime.now(), p_my_handler)
|
update_crontab(datetime.datetime.now(), p_my_handler)
|
||||||
|
|
||||||
|
|
||||||
|
def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler):
|
||||||
|
|
||||||
def sleeping_time(pCurrent_Time):
|
my_scheduler = BackgroundScheduler()
|
||||||
while True:
|
|
||||||
time_difference = datetime.datetime.now() - pCurrent_Time
|
|
||||||
print(time_difference)
|
|
||||||
if float(str(time_difference).split(':')[1]) >=1: # every minute (0:00:03.646070) -> example time code
|
|
||||||
update_crontab(datetime.datetime.now())
|
|
||||||
break
|
|
||||||
|
|
||||||
def update_based_on_crontab(p_user_ids, p_user_crontab):
|
|
||||||
|
|
||||||
my_scheduler = BlockingScheduler()
|
|
||||||
|
|
||||||
print("update based on cron")
|
print("update based on cron")
|
||||||
|
|
||||||
print(len(user_ids)) #Debug
|
print(len(user_ids)) #Debug
|
||||||
|
|
||||||
for i in range(len(p_user_ids)):
|
for i in range(len(p_user_ids)):
|
||||||
print("in loop")
|
|
||||||
cron_split = p_user_crontab[i].split(" ")
|
cron_split = p_user_crontab[i].split(" ")
|
||||||
print(cron_split[4], cron_split[1], cron_split[0], cron_split[3], cron_split[2])
|
print(cron_split[4], cron_split[1], cron_split[0], cron_split[3], cron_split[2])
|
||||||
my_scheduler.add_job(update_for_user, 'cron', day_of_week = cron_split[4] , hour= cron_split[1] , minute = cron_split[0], month= cron_split[3] , day=cron_split[2], args=(p_user_ids[i], ))
|
my_scheduler.add_job(update_for_user, 'cron', day_of_week = cron_split[4] , hour= cron_split[1] , minute = cron_split[0], month= cron_split[3] , day=cron_split[2], args=(p_user_ids[i], p_my_handler ))
|
||||||
|
|
||||||
my_scheduler.start()
|
my_scheduler.start()
|
||||||
|
|
||||||
|
print("60 second sleep")
|
||||||
|
time.sleep( 60 )
|
||||||
|
my_scheduler.shutdown()
|
||||||
|
|
||||||
def update_for_user(p_user_id, p_my_handler):
|
def update_for_user(p_user_id, p_my_handler):
|
||||||
|
|
||||||
share_symbols = []
|
share_symbols = []
|
||||||
|
Loading…
Reference in New Issue
Block a user