My service bus queue trigger will get triggered every time when a new file is landed in blob storage, and the trigger function will perform a post request to Airflow to trigger an airflow job, but doesn't matter if it is a good request with 200 or bad request 404, the trigger will mark as success automatically even when the airflow job does not get triggered, hence, we will lost that message and there is no way to retrieve it back.
I thought 2 solutions, firstly is catch error in Exception, secondly is manually failed the job if code != 200, but none of the solution works.
As we can see if the code, status = 404 and trigger function still marked succeeded. Where did I do wrong in my code? How could I make my logic work?
try:
result = requests.post(
f"http://localhost:8080/api/v1/dags/{dag_id}/dagRunss",
data = json.dumps(data),
headers = header,
auth = ("airflow", "airflow"))
logging.info(result.content.decode('utf-8'))
if result.status_code != 200:
raise ValueError('This is the exception you expect to handle')
except Exception as err:
logging.error(err)