![]() This is only applicable if retries is nonzero.Īn optional string specifying the version of this task definition.įor example, you can provide a name value for the task. If the key matches a previous completed state, that state result will be restored instead of running the task again.Īn optional amount of time indicating how long cached states for this task should be restorable if not provided, cached states will never expire.Īn optional name to distinguish runs of this task this name can be provided as a string template with the task's keyword arguments as variables this name can also be provided via a function that returns a string.Īn optional number of times to retry on task run failure.Īn optional number of seconds to wait before retrying the task after failure. These tags are combined with any tags defined by a prefect.tags context at task runtime.Īn optional callable that, given the task run context and call parameters, generates a string key. If not provided, the description will be pulled from the docstring for the decorated function.Īn optional set of tags to be associated with runs of this task. If not provided, the name will be inferred from the function name.Īn optional string description for the task. Tasks accept the following optional arguments. Examples include retry behavior, names, tags, caching, and more. Tasks allow a great deal of customization via arguments. You also won't be able to use features such as retries with this function call. Prefect won't track task execution in your Prefect backend if you call the task function this way. ![]() Note that in the example above you are only calling the task's function without actually generating a task run. fn ( msg ) def my_flow (): my_second_task ( "Trillian" ) Calling the task from within a flow function creates a new task run:įrom prefect import flow, task def my_first_task ( msg ): print ( f "Hello, " ) def my_second_task ( msg ): my_first_task. Use the decorator to designate a function as a task. Tasks may not be called from other tasks. All tasks must be called from within a flow. You can define your tasks within the same file as your flow definition, or you can define tasks within modules and import them for use in your flow definitions. Tasks also take advantage of automatic Prefect logging to capture details about task runs such as runtime, tags, and final state. This gives you the opportunity to, for example, have a task wait on the completion of another task before executing. Tasks are special because they receive metadata about upstream dependencies and the state of those dependencies before they run, even if they don't receive any explicit data inputs from them. A Prefect task can do almost anything a Python function can do. Tasks are functions: they can take inputs, perform work, and return an output. Tasks enable you to encapsulate elements of your workflow logic in observable units that can be reused across flows and subflows. Tasks are not required - you may define Prefect workflows that consist only of flows, using regular Python statements and functions. A task is a function that represents a discrete unit of work in a Prefect workflow.
0 Comments
Leave a Reply. |