https://prefect.io logo
v

Vladislav Bogucharov

04/27/2021, 1:10 PM
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):
1
z

Zach Angell

04/27/2021, 1:35 PM
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):
j

Jenny

04/27/2021, 1:36 PM
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
v

Vladislav Bogucharov

04/27/2021, 1:55 PM
@Zach Angell Yes, indeed, I am using the state handler. The complete logic looks like this:
Copy code
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.
👍 1
@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?
z

Zach Angell

04/27/2021, 2:01 PM
That state handler looks good to me. We do something similar in our build in handlers
j

Jenny

04/27/2021, 2:05 PM
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.
👍 1
v

Vladislav Bogucharov

04/27/2021, 2:10 PM
Thank you @Zach Angell @Jenny!
👍 2
2 Views