telegram.ext.Job

class telegram.ext.Job(callback, context=None, name=None, job_queue=None, job=None)

Bases: object

This class is a convenience wrapper for the jobs held in a telegram.ext.JobQueue. With the current backend APScheduler, job holds a apscheduler.job.Job instance.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their id is equal.

Note

  • All attributes and instance methods of job are also directly available as attributes/methods of the corresponding telegram.ext.Job object.

  • Two instances of telegram.ext.Job are considered equal, if their corresponding job attributes have the same id.

  • If job isn’t passed on initialization, it must be set manually afterwards for this telegram.ext.Job to be useful.

Parameters
  • callback (callable) –

    The callback function that should be executed by the new job. Callback signature for context based API:

    def callback(CallbackContext)

    a context.job is the telegram.ext.Job instance. It can be used to access its job.context or change it to a repeating job.

  • context (object, optional) – Additional data needed for the callback function. Can be accessed through job.context in the callback. Defaults to None.

  • name (str, optional) – The name of the new job. Defaults to callback.__name__.

  • job_queue (telegram.ext.JobQueue, optional) – The JobQueue this job belongs to. Only optional for backward compatibility with JobQueue.put().

  • job (apscheduler.job.Job, optional) – The APS Job this job is a wrapper for.

callback

The callback function that should be executed by the new job.

Type

callable

context

Optional. Additional data needed for the callback function.

Type

object

name

Optional. The name of the new job.

Type

str

job_queue

Optional. The JobQueue this job belongs to.

Type

telegram.ext.JobQueue

job

Optional. The APS Job this job is a wrapper for.

Type

apscheduler.job.Job

property enabled

Whether this job is enabled.

Type

bool

property next_t

Datetime for the next job execution. Datetime is localized according to tzinfo. If job is removed or already ran it equals to None.

Type

datetime.datetime

property removed

Whether this job is due to be removed.

Type

bool

run(dispatcher)

Executes the callback function independently of the jobs schedule.

schedule_removal()

Schedules this job for removal from the JobQueue. It will be removed without executing its callback function again.