Skip to content

Restart a jobqueue #1972

@grayskripko

Description

@grayskripko

I want to restart a job queue after being stopped.
So, I can start a task task() by a timer and I can stop it.
When I try to start it for the second time and timer() content works great but not task() at all

class MyBot:
        def __init__(self, some_params):
              self.updater = tg.Updater(TOKEN, ...)

        def start_bot(self):
            self.updater.start_pooling()

            def task():                  
                  ...logic...
        
            def timer(update: telegram.Update, context: telegram.ext.CallbackContext):
                context.job_queue.run_repeating(
                    task, poll,
                    context=update.message.chat_id, first=5)

            def stop(update: telegram.Update, context: telegram.ext.CallbackContext):
                context.job_queue.stop()

            handlers = [
                {'command': 'start', 'callback': timer},
                {'command': 'stop', 'callback': stop, 'pass_job_queue': False} ]
            for h in handlers:
                self.updater.dispatcher.add_handler(CommandHandler(**h))

            

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions