Configuration Classes

PollingConfig

class pg_scheduler.PollingConfig(min_interval: float = 0.05, max_interval: float = 2.0, backoff_multiplier: float = 1.5, idle_start_interval: float = 0.5, semaphore_full_interval: float = 1.0, jitter: bool = True)[source]

Bases: object

Configuration for job polling backoff strategy.

Controls how aggressively the scheduler polls for new jobs. Uses exponential backoff when idle (no jobs found) and resets to fast polling when jobs are claimed.

Parameters:
  • min_interval – Seconds to sleep between polls when jobs are actively being claimed. Keep this low for responsive job pickup. (default: 0.05)

  • max_interval – Upper bound in seconds for the backoff sleep. The idle interval will never exceed this value regardless of how long the scheduler has been idle. (default: 2.0)

  • backoff_multiplier – Factor by which the idle interval grows after each empty poll. For example, 1.5 means each successive idle poll sleeps 50% longer than the previous one. Must be >= 1.0. (default: 1.5)

  • idle_start_interval – Initial sleep in seconds when no jobs are found. Subsequent idle polls grow this by backoff_multiplier until max_interval is reached. Resets when jobs are claimed. (default: 0.5)

  • semaphore_full_interval – Seconds to wait before re-checking when all concurrency slots are occupied. (default: 1.0)

  • jitter – When True, adds ±10% random jitter to each sleep to spread out polling across workers and avoid thundering-herd effects. (default: True)

min_interval: float = 0.05
max_interval: float = 2.0
backoff_multiplier: float = 1.5
idle_start_interval: float = 0.5
semaphore_full_interval: float = 1.0
jitter: bool = True
__init__(min_interval: float = 0.05, max_interval: float = 2.0, backoff_multiplier: float = 1.5, idle_start_interval: float = 0.5, semaphore_full_interval: float = 1.0, jitter: bool = True) None

VacuumConfig

class pg_scheduler.VacuumConfig(completed: VacuumPolicy = None, failed: VacuumPolicy = None, cancelled: VacuumPolicy = None, interval_minutes: int = 60, track_metrics: bool = False)[source]

Bases: object

Complete vacuum configuration for the scheduler

completed: VacuumPolicy = None
failed: VacuumPolicy = None
cancelled: VacuumPolicy = None
interval_minutes: int = 60
track_metrics: bool = False
__post_init__()[source]

Set sensible defaults for None policies

__init__(completed: VacuumPolicy = None, failed: VacuumPolicy = None, cancelled: VacuumPolicy = None, interval_minutes: int = 60, track_metrics: bool = False) None

VacuumPolicy

class pg_scheduler.VacuumPolicy(trigger: VacuumTrigger, days: int | None = None, keep_count: int | None = None)[source]

Bases: object

Configuration for a vacuum policy

trigger: VacuumTrigger
days: int | None = None
keep_count: int | None = None
classmethod immediate() VacuumPolicy[source]

Delete immediately when job reaches this status

classmethod after_days(days: int) VacuumPolicy[source]

Delete jobs after N days in this status

classmethod keep_last(count: int) VacuumPolicy[source]

Keep only the last N jobs per job_name in this status

classmethod never() VacuumPolicy[source]

Never automatically clean jobs in this status

__init__(trigger: VacuumTrigger, days: int | None = None, keep_count: int | None = None) None

JobSpec

class pg_scheduler.JobSpec(func: Callable, execution_time: datetime.datetime, args: tuple = (), kwargs: dict = <factory>, priority: pg_scheduler.job_priority.JobPriority = <JobPriority.NORMAL: normal (db_value=5)>, max_retries: int = 0, job_id: str | None = None, misfire_grace_time: Union[int, NoneType, object]=<object object at 0x75fdf91d9e00>)[source]

Bases: object

func: Callable
execution_time: datetime
args: tuple = ()
kwargs: dict
priority: JobPriority = 'normal'
max_retries: int = 0
job_id: str | None = None
misfire_grace_time: int | None | object = <object object>
__init__(func: Callable, execution_time: datetime, args: tuple = (), kwargs: dict = <factory>, priority: JobPriority = <JobPriority.NORMAL: normal (db_value=5)>, max_retries: int = 0, job_id: str | None = None, misfire_grace_time: int | None | object = <object object>) None