Skip to content

ppqueue.Job

Represents a job returned by a PPQueue.

Attributes

callback_result class-attribute instance-attribute

callback_result: str | None = field(
    default=None, init=False
)

Result of the callback for this job.

cancelled class-attribute instance-attribute

cancelled: bool = field(default=False, init=False)

Did this job timeout or was it cancelled?

error class-attribute instance-attribute

error: str | None = field(default=None, init=False)

Exception text for this job, if an error occurred.

finish_timestamp class-attribute instance-attribute

finish_timestamp: float | None = field(
    default=None, init=False
)

Unix timestamp of when this job finished.

idx class-attribute instance-attribute

idx: int | None = field(default=None, init=False)

The ID of this job.

process_timestamp class-attribute instance-attribute

process_timestamp: float | None = field(
    default=None, init=False
)

Unix timestamp of when this job was processed from the working queue.

qid class-attribute instance-attribute

qid: str | None = field(default=None, init=False)

The ID of the queue that ran this job.

result class-attribute instance-attribute

result: Any = field(default=None, init=False)

Result of this job, if it exited gracefully.

start_timestamp class-attribute instance-attribute

start_timestamp: float | None = field(
    default=None, init=False
)

Unix timestamp of when this job started.

submit_timestamp class-attribute instance-attribute

submit_timestamp: float | None = field(
    default=None, init=False
)

Unix timestamp of when this job was submitted.

Functions

get_exit_code

get_exit_code() -> int | None

Exit code of the job.

RETURNS DESCRIPTION
int | None

The exit code of the job if available, otherwise None.

get_finish_timestamp

get_finish_timestamp() -> datetime | None

Returns a datetime object of the time this data finished.

RETURNS DESCRIPTION
datetime | None

A datetime object representing when the job finished, or None if it has not finished.

get_processed_timestamp

get_processed_timestamp() -> datetime | None

Returns a datetime object of the time this data was processed.

RETURNS DESCRIPTION
datetime | None

A datetime object representing when the job was processed, or None if it has not been processed.

get_seconds_running

get_seconds_running() -> float | None

The number of seconds a job was running for.

RETURNS DESCRIPTION
float | None

The duration in seconds that the job was running, or None if the job has not started or finished.

Examples:

from ppqueue import PPQueue
from time import sleep

with PPQueue() as queue:
    for i in range(5):
        jobs = queue.map(sleep, [1, 2, 3])

assert [int(job.get_seconds_running()) for job in jobs] == [1, 2, 3]

get_seconds_total

get_seconds_total() -> float | None

Returns the waiting + running duration of this job.

RETURNS DESCRIPTION
float | None

The total duration in seconds that the job has been in the queue and running, or None if the job has not been submitted.

get_seconds_waiting

get_seconds_waiting() -> float | None

The amount of time a data has spent in the waiting queue.

RETURNS DESCRIPTION
float | None

The duration in seconds that the job has been waiting, or None if the job has not been submitted.

get_start_timestamp

get_start_timestamp() -> datetime | None

Returns a datetime object of the time this data was started.

RETURNS DESCRIPTION
datetime | None

A datetime object representing when the job started, or None if it has not started.

get_submit_timestamp

get_submit_timestamp() -> datetime | None

The time this job was submitted.

RETURNS DESCRIPTION
datetime | None

A datetime object representing when the job was submitted, or None if it has not been submitted.