task — Task specification

This module collects a few task classes that can be used with the scheduler and depgraph modules.

This module defines a dummy Task class that may be used as a base class and extended.

The Task.do method takes two arguments:

  • env is an environment for task execution. The idea of the environment is that tasks may use it to store information about their execution. For instance, a task may create a file and store its location in the environment, so that later tasks may be able to retrieve it. The type of env is really immaterial, but it is probably natural to use a key-value mapping of some kind. Note, however, that most of the tasks defined in the task module hierarchy expect env to be an Env object.

  • config is a Config object describing the configuration for the current run. Tasks may look up global configuration values here.

The Task class models two types of inter-task dependencies. Hard dependencies represent dependencies that are crucial for the execution of the task at hand. If task A has a hard dependency on task B, it means that A cannot run unless B has successfully completed. If B fails, then it makes no sense to run A. On the other hand, if task A has a soft dependency on task B, it means that A will not start before B’s termination, but it makes sense to run A even if B fails.

class valjean.cosette.task.TaskStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Enumeration for the task status. The possible values are:

  • WAITING (the task is waiting to be scheduled)

  • PENDING (the task is under execution)

  • DONE (the task was executed and it succeeded)

  • FAILED (the task was executed and it failed)

  • SKIPPED (the task was skipped by the scheduler; this may happen, for instance, if the one of the task dependencies was not successful)

__format__(format_spec, /)

Default object formatter.

__new__(value)
exception valjean.cosette.task.TaskError[source]

An error that may be raised by Task classes.

class valjean.cosette.task.Task(name, *, deps=None, soft_deps=None)[source]

Base class for other task classes.

__init__(name, *, deps=None, soft_deps=None)[source]

Initialize the task.

Parameters:
  • name (str) – The name of the task. Task names must be unique!

  • deps (list(Task) or None) – The list of (hard) dependencies for this task. It must be either None (i.e. no dependencies) or list of Task objects.

  • soft_deps (list(Task) or None) – The list of soft dependencies for this task. It must be either None (i.e. no dependencies) or list of Task objects.

abstract do(env, config)[source]

Perform a task.

Parameters:

env – The environment for this task.

__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).

add_dependency(dep)[source]

Add an item to the list of dependencies of this task.

depends(other)[source]

Return True if self depends on other.

soft_depends(other)[source]

Return True if self has a soft dependency on other.

class valjean.cosette.task.DelayTask(name, delay=1.0)[source]

Task that waits for the specified number of seconds. This task is useful to test scheduling algorithms under different load conditions.

__init__(name, delay=1.0)[source]

Initialize the task from a given delay.

Parameters:

delay (float) – The amount of time (in seconds) that this task will wait when executed.

do(env, config)[source]

Perform the task (i.e. sleep; I wish my life was like that).

Parameters:

env – The environment. Ignored.

valjean.cosette.task.det_hash(*args)[source]

Produce a deterministic hash for the collection of objects passed as an argument.

valjean.cosette.task.close_dependency_graph(tasks)[source]

Return the tasks along with all their dependencies.

Parameters:

tasks (list) – A list of tasks.

Returns:

The list of tasks, their dependencies, the dependencies of their dependencies and so on.

Return type:

list(Task)