diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index 24b98a2e198..8f4fe8fd08b 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# flake8: noqa E501 # # A library that provides a Python interface to the Telegram Bot API # Copyright (C) 2015-2018 @@ -73,7 +72,8 @@ def put(self, job, next_t=None): Args: job (:class:`telegram.ext.Job`): The ``Job`` instance representing the new job. - next_t (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | :obj:`datetime.datetime` | :obj:`datetime.time`, optional): + next_t (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | \ + :obj:`datetime.datetime` | :obj:`datetime.time`, optional): Time in or at which the job should run for the first time. This parameter will be interpreted depending on its type. @@ -131,7 +131,8 @@ def run_once(self, callback, when, context=None, name=None): job. It should take ``bot, job`` as parameters, where ``job`` is the :class:`telegram.ext.Job` instance. It can be used to access it's ``job.context`` or change it to a repeating job. - when (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | :obj:`datetime.datetime` | :obj:`datetime.time`): + when (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | \ + :obj:`datetime.datetime` | :obj:`datetime.time`): Time in or at which the job should run. This parameter will be interpreted depending on its type. @@ -170,7 +171,8 @@ def run_repeating(self, callback, interval, first=None, context=None, name=None) interval (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta`): The interval in which the job will run. If it is an :obj:`int` or a :obj:`float`, it will be interpreted as seconds. - first (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | :obj:`datetime.datetime` | :obj:`datetime.time`, optional): + first (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` | \ + :obj:`datetime.datetime` | :obj:`datetime.time`, optional): Time in or at which the job should run. This parameter will be interpreted depending on its type. @@ -342,6 +344,11 @@ def jobs(self): with self._queue.mutex: return tuple(job[1] for job in self._queue.queue if job) + def get_jobs_by_name(self, name): + """Returns a tuple of jobs with the given name that are currently in the ``JobQueue``""" + with self._queue.mutex: + return tuple(job[1] for job in self._queue.queue if job and job[1].name == name) + class Job(object): """This class encapsulates a Job. diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index 1b526151b73..0229a55529a 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -238,3 +238,12 @@ def test_warnings(self, job_queue): j.days = ('mon', 'wed') with pytest.raises(ValueError, match='from 0 up to and'): j.days = (0, 6, 12, 14) + + def test_get_jobs(self, job_queue): + job1 = job_queue.run_once(self.job_run_once, 10, name='name1') + job2 = job_queue.run_once(self.job_run_once, 10, name='name1') + job3 = job_queue.run_once(self.job_run_once, 10, name='name2') + + assert job_queue.jobs() == (job1, job2, job3) + assert job_queue.get_jobs_by_name('name1') == (job1, job2) + assert job_queue.get_jobs_by_name('name2') == (job3,) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy