job
— Asynchronous job manager¶
The JobManager
provides a way to schedule jobs and run tasks
asynchronously from within python on the local system. In this case jobs are
callback functions defined by the user.
Warning
The timing and scheduling functions within this module are not designed to be precise to the second.
Functions¶
Classes¶
-
class
JobManager
(use_utc=True, logger_name=None)[source]¶ This class provides a threaded job manager for periodically executing arbitrary functions in an asynchronous fashion.
-
job_add
(callback, parameters=None, hours=0, minutes=0, seconds=0, tolerate_exceptions=True, expiration=None)[source]¶ Add a job to the job manager.
Parameters: - callback (function) – The function to run asynchronously.
- parameters (list, tuple) – The parameters to be provided to the callback.
- hours (int) – Number of hours to sleep between running the callback.
- minutes (int) – Number of minutes to sleep between running the callback.
- seconds (int) – Number of seconds to sleep between running the callback.
- tolerate_execptions (bool) – Whether to continue running a job after it has thrown an exception.
- expiration (int,
datetime.timedelta
,datetime.datetime
) – When to expire and remove the job. If an integer is provided, the job will be executed that many times. If a datetime or timedelta instance is provided, then the job will be removed after the specified time.
Returns: The job id.
Return type:
-
job_count_enabled
()[source]¶ Return the number of enabled jobs.
Returns: The number of jobs that are enabled. Return type: int
-
job_disable
(job_id)[source]¶ Disable a job. Disabled jobs will not be executed.
Parameters: job_id ( uuid.UUID
) – Job identifier to disable.
-
job_exists
(job_id)[source]¶ Check if a job identifier exists.
Parameters: job_id ( uuid.UUID
) – Job identifier to check.Return type: bool
-
job_is_enabled
(job_id)[source]¶ Check if a job is enabled.
Parameters: job_id ( uuid.UUID
) – Job identifier to check the status of.Return type: bool
-
job_is_running
(job_id)[source]¶ Check if a job is currently running. False is returned if the job does not exist.
Parameters: job_id ( uuid.UUID
) – Job identifier to check the status of.Return type: bool
-
job_run
(callback, parameters=None)[source]¶ Add a job and run it once immediately.
Parameters: Returns: The job id.
Return type:
-
now
()[source]¶ Return a
datetime.datetime
instance representing the current time.Return type: datetime.datetime
-
now_is_after
(dt)[source]¶ Check whether the datetime instance described in dt is after the current time.
Parameters: dt ( datetime.datetime
) – Value to compare.Return type: bool
-
now_is_before
(dt)[source]¶ Check whether the datetime instance described in dt is before the current time.
Parameters: dt ( datetime.datetime
) – Value to compare.Return type: bool
-