ecsjobs.jobs.local_command module

class ecsjobs.jobs.local_command.LocalCommand(name, schedule, summary_regex=None, cron_expression=None, command=None, shell=False, timeout=None, script_source=None)[source]

Bases: ecsjobs.jobs.base.Job

Job class to run a local command via subprocess.run(). The output property of this class contains combined STDOUT and STDERR.

Parameters:
  • name (str) – unique name for this job
  • schedule (str) – the name of the schedule this job runs on
  • summary_regex (string or None) – 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.
  • command (str or list) – The command to execute as either a String or a List of Strings, as used by subprocess.run(). If script_source is specified and this parameter is not an empty string or empty list, it will be passed as arguments to the downloaded script.
  • shell (bool) – Whether or not to execute the provided command through the shell. Corresponds to the shell argument of subprocess.run().
  • timeout (int) – An integer number of seconds to allow the command to run. Cooresponds to the timeout argument of subprocess.run().
  • script_source (str) – A URL to retrieve an executable script from, in place of command. This currently supports URLs with http://, https:// or s3:// schemes. HTTP and HTTPS URLs must be directly retrievable without any authentication. S3 URLs will use the same credentials already in use for the session. Note that this setting will cause ecsjobs to download and execute code from a potentially untrusted location.
_get_script(script_url)[source]

Download a script from HTTP/HTTPS or S3 to a temporary path, make it executable, and return the command to execute.

Parameters:script_url (str) – URL to download - HTTP/HTTPS or S3
Returns:path to the downloaded executable script if self._command is an empty string, empty array, or None. Otherwise, a list whose first element is the path to the downloaded executable script, and then contains self._command.
Return type:str
_schema_dict = {'properties': {'command': {'oneOf': [{'type': 'string'}, {'type': 'array', 'items': [{'type': 'string'}]}]}, 'script_source': {'format': 'url', 'pattern': '^(s3|http|https)://.*$', 'type': 'string'}, 'shell': {'type': 'boolean'}, 'timeout': {'oneOf': [{'type': 'integer'}, {'type': 'null'}]}}, 'type': 'object'}

Dictionary describing the configuration file schema, to be validated with jsonschema.

report_description()[source]

Return a one-line description of the Job for use in reports.

Return type:str
run()[source]

Run the command for the job. Either raise an exception or return True if the command exited 0, False if it exited non-zero.

Returns:True if command exited 0, False otherwise.