Thread
#prefect-server
    Mathijs Schoorl

    Mathijs Schoorl

    1 year ago
    I'm playing around with the trigger manual_only. Which seems to work great. Just something I can not really find a good answer to: Is it possible to only ask for an approval if all upstream tasks are successful? It looks like manual_only means it will always ask for approval and keeps the flow running. I would like to have an approval task fail with the status TRIGGERFAIL if any upstream tasks are in a failed state.
    nicholas

    nicholas

    1 year ago
    Hm - I think your best bet here might be to add a task upstream to your manual task that will only continue on
    all_successful
    ; does that make sense?
    Mathijs Schoorl

    Mathijs Schoorl

    1 year ago
    I don't think that will work. As far as I know a task with a trigger 
    all_successful
    will get the status TRIGGERFAIL when one of his upstream tasks fails. So in the end it will finish with a status and then my Task with trigger 
    manual_only
    will fire and set to a paused state instead of the TRIGGERFAIL I want.
    nicholas

    nicholas

    1 year ago
    You know I think you're right
    I think this is worth opening a ticket on the Core repo
    Would you mind doing that and describing what your desired behavior would be?
    One option in the interim might be to use a
    case
    statement to control the instantiation of that task, something like this:
    control_task = ControlTask(trigger=all_successful)(upstream_tasks=[fail_on_purpose])
    
    with case(control_task, True):
      approve = ApproveTransfer(trigger=manual_only)(upstream_tasks=[control_task])
    Mathijs Schoorl

    Mathijs Schoorl

    1 year ago
    I'll give that a try after the weekend. Depending on the outcome I'll create a ticket in the Core repo. Thanks!
    nicholas

    nicholas

    1 year ago
    Sounds good - have a nice weekend! 🙂
    Ah sorry @Mathijs Schoorl - I gave you incomplete advice, you can also write a custom trigger with the form:
    trigger_fn(upstream_states: Set[State]) -> bool
    Mathijs Schoorl

    Mathijs Schoorl

    1 year ago
    Creating my own trigger worked great, thanks:
    def manual_trigger_adv(upstream_states: Dict["core.Edge", "state.State"]) -> bool:
    
        if not all(s.is_successful() for s in _get_all_states_as_set(upstream_states)):
            raise signals.TRIGGERFAIL(
                'Trigger was "manual_only" but some of the upstream tasks failed.'
            )
        if context.get("resume"):
            return True
    
        raise signals.PAUSE('Trigger function is "manual_only"')