ecsjobs.jobs.base module¶
-
class
ecsjobs.jobs.base.
Job
(name, schedule, summary_regex=None, cron_expression=None)[source]¶ Bases:
object
Base class for all Job types/classes.
Parameters: - name (str) – unique name for this job
- schedule (str) – the name of the schedule this job runs on
- summary_regex (
string
orNone
) – A regular expression to use for extracting a string from the job output for use in the summary table. If there is more than one match, the last one will be used. - cron_expression (str) – A cron-like expression parsable by cronex specifying when the job should run. This has the effect of causing runs to skip this job unless the expression matches. It’s recommended not to use any minute specifiers and not to use any hour specifiers if the total runtime of all jobs is more than an hour.
-
_schema_dict
= {'properties': {'class_name': {'type': 'string'}, 'cron_expression': {'type': 'string'}, 'name': {'type': 'string'}, 'schedule': {'type': 'string'}, 'summary_regex': {'type': 'string'}}, 'required': ['name', 'schedule', 'class_name'], 'title': 'Configuration for base Job class', 'type': 'object'}¶ Dictionary describing the configuration file schema, to be validated with jsonschema.
-
duration
¶ Return the duration/runtime of the job, or None if the job did not run.
Returns: job duration Return type: datetime.timedelta
orNone
-
error_repr
¶ Return a detailed representation of the job state for use in error reporting.
Returns: detailed representation of job in case of error Return type: str
-
exitcode
¶ For Job subclasses that result in a command exit code, return the integer exitcode. For Job subclasses that result in a boolean (success / failure) status, return 0 on success or 1 on failure. Returns -1 if the Job has not completed.
Returns: Job exit code or (0 / 1) status Return type: int
-
is_finished
¶ Return whether or not the Job is finished.
Returns: whether or not the Job is finished Return type: bool
-
is_started
¶ Return whether or not the Job has been started.
Returns: whether or not the Job has been started Return type: bool
-
output
¶ Return the output of the Job as a string, or None if the job has not completed.
Returns: Job output Return type: str
-
poll
()[source]¶ For asynchronous jobs (
is_started
is True butis_finished
is False), check if the job has finished yet. If not, returnFalse
. If the job has finished, updateself._finish_time
,self._exit_code
,self._output
andself._finished
and then returnTrue
.This method should never raise exceptions; recoverable exceptions should be handled via internal retry logic on subsequent poll attempts. Retries should be done on the next call of this method; we never want to sleep during this method. Unrecoverable exceptions should set
self._exit_code
,self._output
andself._finished
.Returns: is_finished
Return type: bool
-
report_description
()[source]¶ Return a one-line description of the Job for use in reports.
Return type: str
-
run
()[source]¶ Run the job.
This method sets
self._started
andself._start_time
. If the Job runs synchronously, this method also setsself._finished
,self._exit_code
,self._finish_time
andself._output
.In the case of an exception, this method must still set those attributes as appropriate and then raise the exception.
Returns: True if job finished successfully, False if job finished but failed, or None if the job is still running in the background.
-
schedule_name
¶ Return the configured schedule name for this job.
Returns: schedule name Return type: str
-
skip
¶ Either None if the job should not be skipped, or a string reason describing why the Job should be skipped.
Return type: None
orstr