3

I have the same problem as in this thread

run_daily doesn't do its job. run_once and run_repeating work well.

I do not understand why. I tested your code but task is not carried out

import telegram.ext
from telegram.ext import Updater
import datetime

updater = Updater('My Token', use_context=True)
job = updater.job_queue

def callback_minute(context: telegram.ext.CallbackContext):
    context.bot.send_message(chat_id='My Chat ID', text='One message every minute')

t = datetime.time(20, 2, 00, 000000)
job.run_daily(callback_minute,t,days=(0, 1, 2, 3, 4, 5, 6),context=None,name=None)

updater.start_polling()
updater.idle()

I have tried with this code yet, but it also does not work

from telegram.ext import Updater, CommandHandler
import datetime

def daily_job(bot, update, job_queue):
    """ Running on Mon, Tue, Wed, Thu, Fri = tuple(range(5)) """
    bot.send_message(chat_id='My Chat ID', text='Setting a daily notifications!')
    t = datetime.time(7, 30, 00, 000000)
    job_queue.run_daily(notify_assignees, t, days=tuple(range(5)), context=update)

def notify_assignees(bot, job):
    bot.send_message(chat_id='My Chat ID', text="Some text!")

updater = Updater('My Token')
updater.dispatcher.add_handler(CommandHandler('notify', daily_job, pass_job_queue=True))

updater.start_polling()

In both cases task added to jobs() but not done ...

Ulquiorra
  • 41
  • 4

2 Answers2

1

I found the cause of the problem. Task time is moved back two hours. task that I ordered at 19 was carried out at 21.

This is most easily observed by commissioning two tasks run_daily and run_repeatingand checking .next_t

import telegram.ext
from telegram.ext import Updater
import datetime

updater = Updater('My Token', use_context=True)
job = updater.job_queue

def example_task(context: telegram.ext.CallbackContext):
    context.bot.send_message(chat_id='My Chat ID', text='Hello!')

t = datetime.time(19, 52, 00, 000000)
jobDay = job.run_daily(example_task,t,days=(0, 1, 2, 3, 4, 5, 6))

jobRepeating = job.run_repeating(example_task, 10)

print(jobDay.next_t)
print(jobRepeating.next_t)

updater.start_polling()
updater.idle()
Ulquiorra
  • 41
  • 4
1

I fixed the moved back time issue. Time discrepancy gone in this way.

target_time = datetime.time(hour=2,minute=56).replace(tzinfo=local_timezone)

jobDay = j.run_daily(repeater_func,target_time,days=(0, 1, 2, 3, 4, 5, 6))

print(target_time)
icetin
  • 11
  • 1