How to use the prefect.task function in prefect

To help you get started, we’ve selected a few prefect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrefectHQ / prefect / tests / serialization / test_deserialization / flows / flow_template.py View on Github external
@task(
    cache_for=datetime.timedelta(days=10),
    cache_validator=partial_parameters_only(["x"]),
    result_handler=JSONResultHandler(),
)
def cached_task(x, y):
    pass
github PrefectHQ / prefect / tests / engine / cloud / test_cloud_task_runner.py View on Github external
    @prefect.task(name="test")
    def raise_error():
        raise NameError("I don't exist")
github PrefectHQ / prefect / tests / engine / test_task_runner.py View on Github external
        @prefect.task(cache_for=timedelta(minutes=10))
        def tt(foo):
            pass
github PrefectHQ / prefect / tests / serialization / test_deserialization / flows / flow_template.py View on Github external
@task(name="Big Name", checkpoint=True, result_handler=S3ResultHandler(bucket="blob"))
def terminal_task():
    pass
github PrefectHQ / prefect / tests / tasks / test_control_flow.py View on Github external
    @task
    def skip_task():
        raise prefect.engine.signals.SKIP("not today")
github PrefectHQ / prefect / examples / cached_task.py View on Github external
@task(cache_for=datetime.timedelta(minutes=1, seconds=30))
def return_random_number():
    return random.random()
github PrefectHQ / prefect / examples / flow_state_handler_viz.py View on Github external
@task(max_retries=3, retry_delay=timedelta(seconds=0))
def randomly_fail():
    x = random.random()
    if x > 0.7:
        raise ValueError("x is too large")
github PrefectHQ / prefect / examples / feature_engineering.py View on Github external
@task
def read_csv(
    rootdir: str, table_name: str, nrows: int = None, exclude_cols: List[str] = None
):
    """
    Read the contents of a CSV into a Pandas DataFrame.

    This is built specifically for the file structure of the Lahman database.

    Args:
        - rootdir (str): name of the top-level directory where the data is stored
        - table_name (str): name of the data table to be retrieved
        - nrows (int, optional): defaults to all rows; otherwise, number of rows to load
        - exclude_cols (List[str], optional): columns to be excluded, by name

    Returns:
        - pd.DataFrame: the contents of the CSV
github PrefectHQ / prefect / examples / feature_engineering.py View on Github external
@task
def impute(data: np.ndarray, replacement_dict: Dict[Any, Any]) -> np.ndarray:
    """
    Replace any instances of a set of values with corresponding new values.

    The replacements are provided in a dictionary.
    The keys are the values to be replaced,
    and the values are the values to replace with.

    Args:
        - data (np.ndarray): data in which the replacements should be made
        - replacement_dict (Dict[Any, Any]): what to replace, and what to replace it with

    Returns:
        - np.ndarray: data with values replaced
    """
    for old, new in replacement_dict.items():