task

module of dascore.workflow source

The immutable, fingerprintable unit of work DASCore’s workflows are built of.

A Task is a frozen pydantic model whose fields are the parameters of one operation. Because the parameters are the object, a task can be compared, hashed, written to a file and read back, and identified by a fingerprint: a digest of which task it is, which version of it, and what it was given.

Examples

from dascore.workflow import Task

class AddNumberExample(Task):
    '''Add a number to what it is given.'''
    value: int = 1

    def run(self, number):
        return number + self.value

task = AddNumberExample(value=2)
assert task.run(1) == 3
# The same task, however it was built, has the same fingerprint.
assert task.fingerprint == AddNumberExample(value=2).fingerprint
assert task.fingerprint != AddNumberExample(value=3).fingerprint

Functions

Name Description
intern Return one shared instance for every task which equals the given one.
make_function_task_class Return a Task subclass whose fields are a function’s parameters.
task Turn a function into a Task subclass.

Classes

Name Description
FunctionTask The behaviour a task synthesized from a function has.
Task Base class for a fingerprintable, serializable operation.