https://prefect.io logo
#prefect-community
Title
# prefect-community
d

Dileep Damodaran

06/07/2022, 3:53 AM
Hi all, Is there any reason why a task runs regardless of the case result? I want to run a task only when a parameter is set to True. Implemented this using the Case control flow, but it runs irrespective of the case result. That is even when the parameter is set to False.
k

Kevin Kho

06/07/2022, 3:56 AM
Can you show me a code sample?
d

Dileep Damodaran

06/07/2022, 3:59 AM
Copy code
param_flow_compute_bot_markers_enabled = Parameter(
        "Run Compute Bots Markers", default=True
    )

    with case(param_flow_compute_bot_markers_enabled, True):
        <http://logger.info|logger.info>(f"The flow {flow.name} is enabled")
        registered_bots = _utils.get_configured_bots()
I want to execute certain statements only when param_flow_compute_bot_markers_enabled is True
🙌 1
k

Kevin Kho

06/07/2022, 4:04 AM
This looks right. Maybe you can register and show the schematic?
d

Dileep Damodaran

06/07/2022, 4:55 AM
Sure. if not ‘case’ is there any alternative for conditional execution in prefect?
k

Kevin Kho

06/07/2022, 4:57 AM
No it’s only
case
d

Dileep Damodaran

06/07/2022, 8:08 AM
Copy code
with case(param_flow_compute_bot_markers_enabled, False):
        <http://logger.info|logger.info>(f"The flow {flow.name} is disabled. Skipping flow")

    with case(param_flow_compute_bot_markers_enabled, True):
        <http://logger.info|logger.info>(f"The flow {flow.name} is enabled")
I could see both the the log messages with the above example.
k

Kevin Kho

06/07/2022, 1:56 PM
That’s because the logger is evaluated during Flow creation time. It’s not deferred because it’s not in a task
6 Views