telegram.ext.Job

class telegram.ext.Job(callback, data=None, name=None, job=None, chat_id=None, user_id=None)[source]

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.

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

Changed in version 20.0: * Removed argument and attribute job_queue. * Renamed Job.context to Job.data.

Parameters
  • callback (coroutine function) –

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

    async def callback(context: CallbackContext)
    

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

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

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

  • chat_id (int, optional) –

    Chat id of the chat that this job is associated with.

    New in version 20.0.

  • user_id (int, optional) –

    User id of the user that this job is associated with.

    New in version 20.0.

callback[source]

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

Type

coroutine function

data[source]

Optional. Additional data needed for the callback function.

Type

object

name[source]

Optional. The name of the new job.

Type

str

job[source]

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

Type

apscheduler.job.Job

chat_id[source]

Optional. Chat id of the chat that this job is associated with.

New in version 20.0.

Type

int

user_id[source]

Optional. User id of the user that this job is associated with.

New in version 20.0.

Type

int

property enabled[source]

Whether this job is enabled.

Type

bool

property next_t[source]

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

Warning

This attribute is only available, if the telegram.ext.JobQueue this job belongs to is already started. Otherwise APScheduler raises an AttributeError.

Type

datetime.datetime

property removed[source]

Whether this job is due to be removed.

Type

bool

async run(application)[source]

Executes the callback function independently of the jobs schedule. Also calls telegram.ext.Application.update_persistence().

Changed in version 20.0: Calls telegram.ext.Application.update_persistence().

Parameters

application (telegram.ext.Application) – The application this job is associated with.

schedule_removal()[source]

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