Thread
#prefect-community
    Vladislav Bogucharov

    Vladislav Bogucharov

    1 year ago
    As far as I found out,
    state.TriggerFailed
    is a child of
    state.Failed
    . When one of my tasks fails, then I get the
    state.Failed
    from this task and then from the next task, which actually didn't break, I get
    state.TriggerFailed
    with message TRIGGERFAIL('Trigger was "all_successful" but some of the upstream tasks failed.',). I would like to receive information only about the failed task. At the moment I have implemented the following logic, is this the best practice?
    if isinstance (new_state, state.Failed) and not isinstance (new_state, state.TriggerFailed):
    Zach Angell

    Zach Angell

    1 year ago
    Hi @Vladislav Bogucharov, this logic seems reasonable to me. If you want to dig in deeper, in what context are you using this logic? Is this in a state_handler?
    if isinstance (new_state, state.Failed) and not isinstance (new_state, state.TriggerFailed):
    Jenny

    Jenny

    1 year ago
    Hi @Vladislav Bogucharov - you could also try using an all_finished trigger instead of all_successful - more in the docs here: https://docs.prefect.io/core/getting_started/next-steps.html#signals
    Vladislav Bogucharov

    Vladislav Bogucharov

    1 year ago
    @Zach Angell Yes, indeed, I am using the state handler. The complete logic looks like this:
    def telegram_alarm(task, old_state, new_state):
        if isinstance(new_state, state.Failed) and not isinstance(new_state, state.TriggerFailed):
            flow_name = prefect.context.to_dict()['flow_name']
            task_name = task.name
            error_text = repr(new_state.result)
            message_data = {'chat_id': CHAT_ID, 'text': f'[{flow_name}] - [{task_name}] - {error_text}'}
            <http://requests.post|requests.post>(TELEGRAM_URL + 'sendMessage', data=message_data)
    If I do not additionally specify
    not isinstance (new_state, state.TriggerFailed)
    , then I will receive two messages in telegrams, which does not correspond a little to what I want. One task has broken, I want to receive one message. Just asking if this is the best practice at the moment.
    @Jenny thanks for your answer! It would be a good solution if my function was a task, but it is a state handler. As far as I know, triggers can only be written for tasks?
    Zach Angell

    Zach Angell

    1 year ago
    That state handler looks good to me. We do something similar in our build in handlers
    Jenny

    Jenny

    1 year ago
    Ah yes if you still want the other task to fail (trigger failed) and your concern is about the state handler sending extra notifications then that looks good.
    Vladislav Bogucharov

    Vladislav Bogucharov

    1 year ago
    Thank you @Zach Angell @Jenny!