-
|
Hello there! How can I check that jobs are valid and will execute lately? I have the following code: class ReminderType(Enum):
Daily = 0
Monthly = 1
class Schedule:
def __init__(self, reminder_type: ReminderType, time: datetime.time, days = None):
self.type = reminder_type
self.time = time
self.days = days
tz = pytz.timezone(...)
SCHEDULES = [
Schedule(ReminderType.Monthly, datetime.time(hour=10, tzinfo=tz), -1),
Schedule(ReminderType.Daily, datetime.time(hour=11, minute=35, tzinfo=tz), (0, 1, 2, 3, 4, 5, 6))
]
if __name__ == '__main__':
application = ApplicationBuilder().token(TOKEN).build()
job_queue = application.job_queue
for schedule in SCHEDULES:
print(schedule.time)
if schedule.type == ReminderType.Daily:
job_daily = job_queue.run_daily(callback, schedule.time, schedule.days)
elif schedule.type == ReminderType.Monthly:
job_monthly = job_queue.run_monthly(callback, schedule.time, schedule.days)
application.run_polling()
I just tried to start a bot at 11:30 and it didn't call callback at 11:35. Also I tried to print job.next_t but it is always None (perhaps it is ok regarding docs). In additional job_*.enabled is always false, is it ok or I do something wrong here? |
Beta Was this translation helpful? Give feedback.
-
|
This might be because the job queue isnt initialized yet? This is purely based on vibes, but try moving it to the post init function https://docs.python-telegram-bot.org/en/stable/telegram.ext.applicationbuilder.html#telegram.ext.ApplicationBuilder.post_init |
Beta Was this translation helpful? Give feedback.
-
|
Please also switch to zoneinfo timezone objects. We have deprecated support for pytz. Moreover, with pytz it's not enough to pass the time zone to the datetime constricter to make the date time time zone aware. |
Beta Was this translation helpful? Give feedback.
I'm dumbass, my bad. I passed datetime.timezone.utc (which equals UTC+0), but I'm in UTC+3, that's why nothing worked. I changed it onto datetime.timezone(datetime.timedelta(hours=3)) and now they works!