baobabsoluciones / cornflow

An open source multi-solver optimization server with a REST API.
https://baobabsoluciones.github.io/cornflow/
Apache License 2.0
19 stars 3 forks source link

Be able to automatically send an email when an execution succeeds #559

Open marioncottard opened 4 days ago

marioncottard commented 4 days ago

Is your feature request related to a problem? Please describe. Currently, ApplicationCore accepts a notify property and, if it is set to True, Airflow automatically sends an email to the adress defined in the NOTIFICATION_EMAIL environment variable if an execution fails. No such option exists to send an email when an execution finishes successfully.

Describe the solution you'd like It would be convenient to have a similar funcionality to automatically send an email when an execution finishes succesfully. We could have a separate boolean property notify_successes in ApplicationCore, and use the on_success_callback to send the email. Ideally, it would be convenient to have a default template for the email, but that could be customized in the Application. It would also be convenient to be able to specify in the Application the name of the environment variable that contains the emails (because when several dags are deployed on a same server, we could want the emails to be sent to a different user for each). We should also have the option to send the email to several users instead of just one.

Describe alternatives you've considered For now, when developping a DAG, it is possible to reproduce this behavior by sending the email at the end of the solve() function of the solvers, just before the return. However, if an error occurs after (for example, while ApplicationCore.solve() is executing the solution checks or sending the results to the server), the email will have been sent before the error occurs.

Additional context I think the possibility to have a default template for the email that could be customized and the possibility to specify the name of the environment variable that contains the email addresses are funcionalities that should be extended to the failure emails as well.

ggsdc commented 4 days ago

More info for the issue:

https://stackoverflow.com/questions/76458756/pass-in-the-return-value-of-same-task-to-on-success-callback-parameter

The return value of the solve task should be the status codes that we currently use so that the callback can get them from the context with the xcom_pull function.