How to catch failed job in python script

Hi

def OnChange(changeType, level, resource):
    def __send_instance_through_peers(instance_id):
        try:
            orthanc.RestApiPost('/peers/server/store', json.dumps({
                "Resources" : [instance_id],
                "Synchronous":False
            }))
        except Exception as e:
            __store_failed_instance_id(instance_id)

    if changeType == orthanc.ChangeType.NEW_INSTANCE: 
        __send_instance_through_peers(resource)

orthanc.RegisterOnChangeCallback(OnChange)

I want to catch it and resend it later on failure. But in logs i see: JobsRegistry.cpp:504] Job has completed with failure.

But it doesn’t catch, __store_failed_instance_id function is not being called

You should listen to changeType == orthanc.ChangeType.JOB_FAILURE