I have a class
that has triggers, and I'd like to update these triggers when the job hit the proper time.
My class:
class SetTrigger(object):
def __init__(self):
self.set_work = False
self.set_reload = False
self.set_refresh = False
def UpdateSetRefresh(self):
self.set_refresh = True
return self.set_refresh
def UpdateSetWork(self):
self.set_work = True
return self.set_work
def UpdateSetReload(self):
self.set_reload = True
return self.set_reload
If I set the variable to get the value from the function as below I get one error.
trigger = SetTrigger()
set_refresh = trigger.UpdateSetRefresh()
Error:
func must be a callable or a textual reference to one
I already tried to call trigger.UpdateSetRefresh
but the variable set_refresh
doesn't change to True
. If I call trigger.UpdateSetRefresh()
it gives me the same error above.
How can I call the function UpdateSetRefresh
from class SetTrigger
in APScheduler job as below?
I tried:
scheduler.add_job(trigger.UpdateSetRefresh, 'interval', seconds=20, id='1', name='refresh_hereoes_positions', misfire_grace_time=180)
[EDIT]
Example that trigger.UpdateSetRefresh
is not returning True
as I need:
import tzlocal
import time
import os
from bot import SetTrigger
from apscheduler.schedulers.asyncio import AsyncIOScheduler
trigger = SetTrigger()
scheduler = AsyncIOScheduler(timezone=str(tzlocal.get_localzone()))
scheduler.add_job(trigger.UpdateSetRefresh, 'interval', seconds=3)
scheduler.start()
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2)
print(trigger.set_refresh)
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
Output:
Press Ctrl+Break to exit
False
False
False