Some of the tasks I run in Airflow occasionally fail for various reasons. Some I catch and others are new and aren't excepted. I want to get exit code 1 in order to receive a notification of such failures.
Below is an example of an error I didn't except, is there a way to have ValueError yield exit code 1?
[2019-06-13 12:56:13,630] {bash_operator.py:127} INFO - ValueError: year 43631 is out of range
[2019-06-13 12:56:13,870] {bash_operator.py:127} INFO - 2019-06-13 12:56:13,869 - ODL - INFO - Closing db connection
[2019-06-13 12:56:13,870] {bash_operator.py:127} INFO - 2019-06-13 12:56:13,870 - ODL - INFO - End
[2019-06-13 12:56:13,990] {bash_operator.py:131} INFO - Command exited with return code 0
[2019-06-13 12:56:17,556] {logging_mixin.py:95} INFO - [2019-06-13 12:56:17,555] {jobs.py:2562} INFO - Task exited with return code 0
I also have other bits of code where the try block uses sys.exit(1)
. However, it is not raised, do I need to raise this error in order to exit with 1?
I've tried using sys.exit(1) in my try blocks.
if count==0:
self._logger.error("Missing data, nothing was loaded")
sys.exit(1)
else:
self._logger.info("Data is present, safe to load to prod!")
I expected to get the following in order to be notified of the failure.
2019-06-13 12:56:17,556] {logging_mixin.py:95} INFO - [2019-06-13 12:56:17,555] {jobs.py:2562} INFO - Task exited with return code 1