better error handling for EventGrid calls that you want to retry
The Microsoft sample documentation (link below) suggests using a Run method with void return type. This doesn't allow convenient handling of errors that you want to handle by getting EventGrid to retry invoking the Azure Function again after a period. For example, my Azure Function sends a message to a server (Azure Container Instance) which may be down. In this situation I want EventGrid to invoke my Azure Function again after a period when the server might be up. However, with a void return type my only option seems to be that of throwing an exception (InvalidOperation?). Agreed, I could use Run([(HttpTrigger(…)]…). However, what's the point of having [EventGridTrigger] if it's not going to be used?
By the way, I tried using a return type of HttpResponseMessage with Run[EventGridTrigger] and whilst it built, it reported an error at runtime Cannot bind parameter '$return' to type HttpResponseMessage&.
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
Have plans to use queues behind the scenes which would add some durability
Oliver Tomlinson commented
I initially thought the same, but came to the conclusion of "why not just throw an exception?"
EventGrid has a simple job and that is to keep trying to deliver the message to the subscriber until it is completed sucessfully.
EventGrid really doesn't care *why* your function failed, I assume it treats any non-200 response as a failure and will invoke retries until it completes successfully or the 24 hour retry period elapses.
My opinion but having to explicitly return a Type that defines the success is unnecessary in this particular binding, as the EventGridTrigger is abstracting you from the complications of returning success or failure state.