Skip to content

base

Base class for backend jobs.

This module provides the base class for backend jobs in the Eleanor system. The BaseJob class is designed to be subclassed and extended to create custom job implementations.

The BaseJob class includes functionality for scheduling job execution based on either a cron expression or a fixed interval. It also handles job setup, execution, and shutdown operations.

Classes

BaseJob

Bases: ABC, BaseDataModel

Base class for backend jobs

Attributes

cron class-attribute instance-attribute
cron: str | None = Field(
    default=None,
    title="Trigger Cron Expression",
    description="Cron expression used to trigger when the job is invoked, this field is mutually exclusive with 'interval'. See: https://en.wikipedia.org/wiki/Cron",
    frozen=True,
)
interval class-attribute instance-attribute
interval: float | None = Field(
    default=None,
    ge=0.0,
    title="Trigger Interval",
    description="Inteval in seconds to trigger the job. This field is mutually exclusive with 'cron'. An inter value of 0 will cause the job to trigger without a wait time in between executions.",
    frozen=True,
)
name class-attribute instance-attribute
name: str = Field(
    ...,
    title="Job Name",
    description="Name of the job, used to identntify job thread name and job activities in the logs.",
    frozen=True,
)
retry_wait class-attribute instance-attribute
retry_wait: int = Field(
    default=10,
    title="Retry Wait Time",
    description="If an error is raised at any point in the job loop this is the wait time in seconds before the job will attempt to restart.",
    frozen=True,
)
trigger_count class-attribute instance-attribute
trigger_count: int = Field(
    default=0,
    title="Trigger Counter",
    description="Indicates the mumber of times the job has been triggered",
)
trigger_on_start class-attribute instance-attribute
trigger_on_start: bool = Field(
    default=False,
    title="Trigger on Startup",
    description="If True, the job will trigger immediately upon startup instead of waiting for the next trigger interval.",
    frozen=True,
)

Functions

init_env
init_env() -> BaseJob
request_stop
request_stop() -> None

Requests the job to stop.

This method sets the stop event and wakes up the job if it’s sleeping.

start
start() -> None

Starts the job by starting the worker thread.

Raises:

validate_cron classmethod
validate_cron(v: str) -> str
validate_env
validate_env() -> BaseJob
wait_until_done
wait_until_done(timeout: float | None = None) -> None

Waits for the job to finish gracefully.

Parameters:

  • timeout (float | None, default: None ) –

    The maximum time to wait for the job to finish, in seconds. If None, it will wait forever.

Raises:

  • JobException

    If the job’s worker thread is still alive after the join timeout.

Returns:

  • None

    None

JobException

Bases: Exception

Job control related exception

Functions