ecsjobs.jobs.ecs_task module

class ecsjobs.jobs.ecs_task.EcsTask(name, schedule, summary_regex=None, cron_expression=None, cluster_name=None, task_definition_family=None, overrides=None, network_configuration=None)[source]

Bases: ecsjobs.jobs.base.Job

Class to run an ECS Task asynchronously; starts the task with the run() method and then uses poll() to wait for it to finish. Sets exitcode according to:

  • if only one container in the task, the exit code of that container
  • otherwise, the maximum exit code of all containers
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.
  • cluster_name (str) – name of the ECS cluster to run the task on
  • task_definition_family (str) – Name of the Task Definition family to run
  • overrides (dict) – RunTask overrides hash/mapping/dict to pass to ECS RunTask API call, as specified in the documentation for ECS.Client.run_task()
  • networkConfiguration (dict) – RunTask networkConfiguration parameter to pass to ECS API call, as specified in the documentation for ECS.Client.run_task()
_log_info_for_task(task_family)[source]

Return a dictionary of container name to 2-tuple of Log Group Name and Log Stream Prefix, for each container in the specified Task Definition that uses the awslogs log driver.

Parameters:task_family (str) – task family name to return log settings for
Returns:dictionary of container name to 2-tuple of Log Group Name and Log Stream Prefix, for each container in the specified Task Definition that uses the awslogs log driver
Return type:dict
_output_for_task_container(taskid, cont_name)[source]

Update self.output with the CloudWatch logs for the containers in the task.

Parameters:
  • taskid (str) – ECS Task ID
  • cont_name (str) – container name in the task
Returns:

CloudWatch logs for the container

Return type:

str

_schema_dict = {'properties': {'cluster_name': {'type': 'string'}, 'network_configuration': {'type': 'object'}, 'overrides': {'type': 'object'}, 'task_definition_family': {'type': 'string'}}, 'required': ['cluster_name', 'task_definition_family'], 'type': 'object'}

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

poll()[source]

Poll to check status on the task. If STOPPED, set this Job as finished and collect report information.

Returns:whether or not the Task 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 command for the job. Output and exit code will be captured by poll(), according to self._task_id.

Returns:None