telegram.ext.jobqueue module¶
This module contains the classes JobQueue and Job.
-
class
telegram.ext.jobqueue.Days¶ Bases:
object-
EVERY_DAY= (0, 1, 2, 3, 4, 5, 6)¶
-
FRI= 4¶
-
MON= 0¶
-
SAT= 5¶
-
SUN= 6¶
-
THU= 3¶
-
TUE= 1¶
-
WED= 2¶
-
-
class
telegram.ext.jobqueue.Job(callback, interval, repeat=True, context=None, days=(0, 1, 2, 3, 4, 5, 6))¶ Bases:
objectThis class encapsulates a Job
-
callback¶ function
-
interval¶ float
-
days¶ (tuple)
-
repeat¶ bool
-
name¶ str
-
enabled¶ bool – Boolean property that decides if this job is currently active
Parameters: - callback (function) – The callback function that should be executed by the Job. It should
take two parameters
botandjob, wherejobis theJobinstance. It can be used to terminate the job or modify its interval. - interval ([int, float, datetime.timedelta]) – The interval in which the job will execute its
callback function.
intandfloatwill be interpreted as seconds. - repeat (Optional[bool]) – If this job should be periodically execute its callback function
(
True) or only once (False). Defaults toTrue - context (Optional[object]) – Additional data needed for the callback function. Can be
accessed through
job.contextin the callback. Defaults toNone - days (Tuple) – Defines on which days the job should be ran.
-
enabled
-
is_enabled()¶
-
job_queue= None¶
-
run(bot)¶ Executes the callback function
-
schedule_removal()¶ Schedules this job for removal from the
JobQueue. It will be removed without executing its callback function again.
-
set_enabled(status)¶
-
-
class
telegram.ext.jobqueue.JobQueue(bot, prevent_autostart=None)¶ Bases:
objectThis class allows you to periodically perform tasks with the bot.
-
queue¶ PriorityQueue
-
bot¶ telegram.Bot
Parameters: bot (telegram.Bot) – The bot instance that should be passed to the jobs - Deprecated: 5.2
- prevent_autostart (Optional[bool]): Thread does not start during initialisation. Use start method instead.
-
jobs()¶ Returns a tuple of all jobs that are currently in the
JobQueue
-
put(job, next_t=None)¶ Queue a new job.
Parameters: - job (telegram.ext.Job) – The
Jobinstance representing the new job - next_t (Optional[int, float, datetime.timedelta]) – Time in which the job
should be executed first. Defaults to
job.interval.intandfloatwill be interpreted as seconds.
- job (telegram.ext.Job) – The
-
start()¶ Starts the job_queue thread.
-
stop()¶ Stops the thread
-
tick()¶ Run all jobs that are due and re-enqueue them with their interval.
-