From e9a6b60e3e8b21388eb5a1b414cdeb2fa4d75dd7 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Fri, 15 Dec 2017 12:43:11 +0330 Subject: [PATCH 1/6] select job based on name of job By selecting jobs based on their names users can manage jobs in job_queue. This new function return a tuple of jobs with the same name given as parameter. --- telegram/ext/jobqueue.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index 78258ba4628..cdbc6b3ba54 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -348,6 +348,11 @@ def jobs(self): return tuple(job[1] for job in self.queue.queue if job) + def select_job(self, name): + """Returns a tuple of all jobs that are currently in the ``JobQueue`` and have the given name.""" + + 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. From d415ea5a993b699a7270ad5c2459c4b3c9aa898a Mon Sep 17 00:00:00 2001 From: Mehdi Date: Fri, 15 Dec 2017 13:15:56 +0330 Subject: [PATCH 2/6] Update jobqueue.py --- telegram/ext/jobqueue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index cdbc6b3ba54..7c4e66722ae 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -349,7 +349,7 @@ def jobs(self): return tuple(job[1] for job in self.queue.queue if job) def select_job(self, name): - """Returns a tuple of all jobs that are currently in the ``JobQueue`` and have the given name.""" + """Returns a tuple of jobs with the given name that are currently in the ``JobQueue``""" return tuple(job[1] for job in self.queue.queue if job and job[1].name==name) From 5cbb5b95756e0f4675615dc54a95ef4f0c637f14 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Sun, 31 Dec 2017 05:38:19 +0330 Subject: [PATCH 3/6] Add space around '==' because of code style --- telegram/ext/jobqueue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index 7c4e66722ae..942af72b804 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -351,7 +351,7 @@ def jobs(self): def select_job(self, name): """Returns a tuple of jobs with the given name that are currently in the ``JobQueue``""" - return tuple(job[1] for job in self.queue.queue if job and job[1].name==name) + return tuple(job[1] for job in self.queue.queue if job and job[1].name == name) class Job(object): From 40a0cd1afb24da2917ea335b7539a1a0da7549f1 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 14:25:27 +0200 Subject: [PATCH 4/6] Add unitest for JobQueue.jobs() & JobQueue.get_jobs_by_name() --- tests/test_jobqueue.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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,) From 02b5bbe122b095b8ab5fc3728f3403a45ea9e29b Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 14:27:52 +0200 Subject: [PATCH 5/6] Rename select_job() -> get_jobs_by_name() and use queue mutex --- telegram/ext/jobqueue.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index e576ca3cada..23faa73081d 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -342,10 +342,10 @@ def jobs(self): with self._queue.mutex: return tuple(job[1] for job in self._queue.queue if job) - def select_job(self, name): + def get_jobs_by_name(self, name): """Returns a tuple of jobs with the given name that are currently in the ``JobQueue``""" - - return tuple(job[1] for job in self.queue.queue if job and job[1].name == name) + with self._queue.mutex: + return tuple(job[1] for job in self._queue.queue if job and job[1].name == name) class Job(object): From c78a7109bc1cad0edfcc9662f2d255930c68b986 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sun, 18 Feb 2018 14:29:25 +0200 Subject: [PATCH 6/6] jobqueue: Fix documentation style --- telegram/ext/jobqueue.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index 23faa73081d..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. 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