Skip to content

Commit 02af1ea

Browse files
committed
jobqueue: cosmetic fixes
1 parent c4a8ee5 commit 02af1ea

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

telegram/ext/jobqueue.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626

2727
class JobQueue(object):
28-
"""
29-
This class allows you to periodically perform tasks with the bot.
28+
"""This class allows you to periodically perform tasks with the bot.
3029
3130
Attributes:
3231
queue (PriorityQueue):
@@ -47,17 +46,16 @@ def __init__(self, bot):
4746
self._running = False
4847

4948
def put(self, job, next_t=None, prevent_autostart=False):
50-
"""
51-
Queue a new job. If the JobQueue is not running, it will be started.
49+
"""Queue a new job. If the JobQueue is not running, it will be started.
5250
5351
Args:
5452
job (Job): The ``Job`` instance representing the new job
5553
next_t (Optional[float]): Time in seconds in which the job should be executed first.
5654
Defaults to ``job.interval``
5755
prevent_autostart (Optional[bool]): If ``True``, the job queue will not be started
5856
automatically if it is not running. Defaults to ``False``
59-
"""
6057
58+
"""
6159
job.job_queue = self
6260

6361
if next_t is None:
@@ -66,7 +64,7 @@ def put(self, job, next_t=None, prevent_autostart=False):
6664
now = time.time()
6765
next_t += now
6866

69-
self.logger.debug('Putting a %s with t=%f' % (job.name, next_t))
67+
self.logger.debug('Putting job %s with t=%f', job.name, next_t)
7068
self.queue.put((next_t, job))
7169

7270
# Wake up the loop if this job should be executed next
@@ -80,35 +78,36 @@ def put(self, job, next_t=None, prevent_autostart=False):
8078

8179
def tick(self):
8280
"""
83-
Run all jobs that are due and re-enqueue them with their interval
81+
Run all jobs that are due and re-enqueue them with their interval.
82+
8483
"""
8584
now = time.time()
8685

87-
self.logger.debug('Ticking jobs with t=%f' % now)
86+
self.logger.debug('Ticking jobs with t=%f', now)
8887

8988
while not self.queue.empty():
9089
t, job = self.queue.queue[0]
91-
self.logger.debug('Peeked at %s with t=%f' % (job.name, t))
90+
self.logger.debug('Peeked at %s with t=%f', job.name, t)
9291

9392
if t <= now:
9493
self.queue.get()
9594

9695
if job._remove.is_set():
97-
self.logger.debug('Removing job %s' % job.name)
96+
self.logger.debug('Removing job %s', job.name)
9897
continue
9998

10099
elif job.enabled:
101-
self.logger.debug('Running job %s' % job.name)
100+
self.logger.debug('Running job %s', job.name)
102101

103102
try:
104103
job.run(self.bot)
105104

106105
except:
107106
self.logger.exception(
108-
'An uncaught error was raised while executing job %s' % job.name)
107+
'An uncaught error was raised while executing job %s', job.name)
109108

110109
else:
111-
self.logger.debug('Skipping disabled job %s' % job.name)
110+
self.logger.debug('Skipping disabled job %s', job.name)
112111

113112
if job.repeat:
114113
self.put(job)
@@ -127,6 +126,7 @@ def tick(self):
127126
def start(self):
128127
"""
129128
Starts the job_queue thread.
129+
130130
"""
131131
self.__lock.acquire()
132132

@@ -135,7 +135,7 @@ def start(self):
135135
self.__lock.release()
136136
job_queue_thread = Thread(target=self._start, name="job_queue")
137137
job_queue_thread.start()
138-
self.logger.debug('Job Queue thread started')
138+
self.logger.debug('%s thread started', self.__class__.__name__)
139139

140140
else:
141141
self.__lock.release()
@@ -144,8 +144,8 @@ def _start(self):
144144
"""
145145
Thread target of thread ``job_queue``. Runs in background and performs ticks on the job
146146
queue.
147-
"""
148147
148+
"""
149149
while self._running:
150150
self.__tick.wait(self._next_peek and self._next_peek - time.time())
151151

@@ -156,7 +156,7 @@ def _start(self):
156156

157157
self.tick()
158158

159-
self.logger.debug('Job Queue thread stopped')
159+
self.logger.debug('%s thread stopped', self.__class__.__name__)
160160

161161
def stop(self):
162162
"""
@@ -215,6 +215,7 @@ def schedule_removal(self):
215215
"""
216216
Schedules this job for removal from the ``JobQueue``. It will be removed without executing
217217
its callback function again.
218+
218219
"""
219220
self._remove.set()
220221

0 commit comments

Comments
 (0)