0

How can I specify a function to run when a DAG fails using the taskflow api? Using the old style I am able to specify a function to run on_failure but I cannot figure out or find documentation to do it using the taskflow api with the DAG and task operators.

Chromey
  • 97
  • 1
  • 11
  • what is wrong with `'on_failure_callback': task_failure_func` ? – balderman Sep 08 '21 at 18:35
  • I have tried that but the function is never called. Here is the task: `@task(on_failure_callback=on_failure) def error(): raise ValueError('fail') ` Here is the function I am trying to call: `def on_failure(): msg = pymsteams.connectorcard('webhook url') msg.title('DAG Exception') msg.text('\n') section = pymsteams.cardsection() section.title('Tellus Accounting DAG Failed') section.addImage('https://i.imgur.com/JHnIreh.png') msg.addSection(section) msg.send() ` – Chromey Sep 08 '21 at 19:07
  • Please [edit] your question to add code, rather than post in comments where it's much less readable and liable to deletion. – David Buck Sep 09 '21 at 06:52

1 Answers1

0

The @dag decorator accepts all arguments that you can pass to when creating DAG instance, especially on_failure_callback. Same goes for @task decorator.

Also the on_failure_callback should be a function accepting context argument. In your example it's not, is there no Error when executing on_failure_callback error?

Tomasz Urbaszek
  • 710
  • 5
  • 12