# Task
# Task
class
prefect.core.task.Task
(name=None, slug=None, tags=None, max_retries=None, retry_delay=None, timeout=None, trigger=None, skip_on_upstream_skip=True, cache_for=None, cache_validator=None, cache_key=None, checkpoint=None, result_handler=None, state_handlers=None, on_failure=None, log_stdout=False, result=None, target=None)[source]The Task class which is used as the full representation of a unit of work.
This Task class can be used directly as a first class object where it must be inherited from by a class that implements the run
method. For a more functional way of generating Tasks, see the task decorator.
Inheritance example:
class AddTask(Task):
def run(self, x, y):
return x + y
Note: The implemented run
method cannot have *args
in its signature. In addition, the following keywords are reserved: upstream_tasks
, task_args
and mapped
.
An instance of a Task
can be used functionally to generate other task instances with the same attributes but with different values bound to their run
methods.
Example:
class AddTask(Task):
def run(self, x, y):
return x + y
a = AddTask()
with Flow("My Flow") as f:
t1 = a(1, 2) # t1 != a
t2 = a(5, 7) # t2 != a
To bind values to a Task's run method imperatively (and without making a copy), see Task.bind
.
Args:
name (str, optional)
: The name of this taskslug (str, optional)
: The slug for this task. Slugs are required and must be unique within any flow; if not provided a random UUID will be generated.tags ([str], optional)
: A list of tags for this taskmax_retries (int, optional)
: The maximum amount of times this task can be retriedretry_delay (timedelta, optional)
: The amount of time to wait until task is retriedtimeout (int, optional)
: The amount of time (in seconds) to wait while running this task before a timeout occurs; note that sub-second resolution is not supportedtrigger (callable, optional)
: a function that determines whether the task should run, based on the states of any upstream tasks.skip_on_upstream_skip (bool, optional)
: ifTrue
, if any immediately upstream tasks are skipped, this task will automatically be skipped as well, regardless of trigger. By default, this prevents tasks from attempting to use either state or data from tasks that didn't run. IfFalse
, the task's trigger will be called as normal, with skips considered successes. Defaults toTrue
.cache_for (timedelta, optional, DEPRECATED)
: The amount of time to maintain a cache of the outputs of this task. Useful for situations where the containing Flow will be rerun multiple times, but this task doesn't need to be.cache_validator (Callable, optional, DEPRECATED)
: Validator that will determine whether the cache for this task is still valid (only required ifcache_for
is provided; defaults toprefect.engine.cache_validators.duration_only
)cache_key (str, optional, DEPRECATED)
: if provided, acache_key
serves as a unique identifier for this Task's cache, and can be shared across both Tasks and Flows; if not provided, the Task's name will be used if running locally, or the Task's database ID if running in Cloudcheckpoint (bool, optional)
: if this Task is successful, whether to store its result using theresult_handler
available during the run; Also note that checkpointing will only occur locally ifprefect.config.flows.checkpointing
is set toTrue
result_handler (ResultHandler, optional, DEPRECATED)
: the handler to use for retrieving and storing state results during execution; if not provided, will default to the one attached to the Flowresult (Result, optional)
: the result instance used to retrieve and store task results during executiontarget (str, optional)
: location to check for task Result. If a result exists at that location then the task run will enter a cached state.target
strings can be templated formatting strings which will be formatted at runtime with values fromprefect.context
state_handlers (Iterable[Callable], optional)
: A list of state change handlers that will be called whenever the task changes state, providing an opportunity to inspect or modify the new state. The handler will be passed the task instance, the old (prior) state, and the new (current) state, with the following signature:state_handler(task: Task, old_state: State, new_state: State) -> Optional[State]
If multiple functions are passed, then thenew_state
argument will be the result of the previous handler.on_failure (Callable, optional)
: A function with signaturefn(task: Task, state: State) -> None
that will be called anytime this Task enters a failure statelog_stdout (bool, optional)
: Toggle whether or not to send stdout messages to the Prefect logger. Defaults toFalse
.
TypeError
: iftags
is of typestr
TypeError
: iftimeout
is not of typeint
methods: |
---|
prefect.core.task.Task.bind (*args, mapped=False, upstream_tasks=None, flow=None, **kwargs)[source] |
Binding a task to (keyword) arguments creates a keyed edge in the active Flow that will pass data from the arguments (whether Tasks or constants) to the Task's
|
prefect.core.task.Task.copy (**task_args)[source] |
Creates and returns a copy of the current Task.
|
prefect.core.task.Task.inputs ()[source] |
Describe the inputs for this task. The result is a dictionary that maps each input to a
|
prefect.core.task.Task.is_equal (other)[source] |
Produces a Task that evaluates
|
prefect.core.task.Task.is_not_equal (other)[source] |
Produces a Task that evaluates
|
prefect.core.task.Task.map (*args, upstream_tasks=None, flow=None, task_args=None, **kwargs)[source] |
Map the Task elementwise across one or more Tasks. Arguments that should not be mapped over should be placed in the
will map over the values of X , but not over the values of Y Args:
|
prefect.core.task.Task.not_ ()[source] |
Produces a Task that evaluates
|
prefect.core.task.Task.or_ (other)[source] |
Produces a Task that evaluates
|
prefect.core.task.Task.outputs ()[source] |
Get the output types for this task.
|
prefect.core.task.Task.run ()[source] |
The
|
prefect.core.task.Task.serialize ()[source] |
Creates a serialized representation of this task
|
prefect.core.task.Task.set_dependencies (flow=None, upstream_tasks=None, downstream_tasks=None, keyword_tasks=None, mapped=False, validate=None)[source] |
Set dependencies for a flow either specified or in the current context using this task
|
prefect.core.task.Task.set_downstream (task, flow=None, key=None, mapped=False)[source] |
Sets the provided task as a downstream dependency of this task.
|
prefect.core.task.Task.set_upstream (task, flow=None, key=None, mapped=False)[source] |
Sets the provided task as an upstream dependency of this task.
|
# Parameter
A Parameter is a special task that defines a required flow input.
A parameter's "slug" is automatically -- and immutably -- set to the parameter name. Flows enforce slug uniqueness across all tasks, so this ensures that the flow has no other parameters by the same name.
Args:
name (str)
: the Parameter name.required (bool, optional)
: If True, the Parameter is required and the default value is ignored.default (any, optional)
: A default value for the parameter. If the default is not None, the Parameter will not be required.tags ([str], optional)
: A list of tags for this parameter
methods: |
---|
prefect.core.task.Parameter.copy (name, **task_args)[source] |
Creates a copy of the Parameter with a new name.
|
prefect.core.task.Parameter.run ()[source] |
The
|
prefect.core.task.Parameter.serialize ()[source] |
Creates a serialized representation of this parameter
|
This documentation was auto-generated from commit n/a
on June 17, 2020 at 17:27 UTC
← Flow Cache Validators →