Invoke-WebRequest in the background

A follow-up to this older post. There I had an Azure Function that was calling another Azure Function like so:

Let’s call these Function A and Function B. Function A is called by a Logic App using a webhook. Function A then calls Function B via Invoke-WebRequest after which it is supposed to exit. Function B will then call the Logic App’s callback URL once its done.

Occassionally though, Function A wouldn’t exit. Instead it would sort of hang around, causing the Logic App to call it again because it’s like “I haven’t heard from Function A, maybe something went wrong…” and so Function A calls Function B again. This would happen some 5-6 times.

I figured what I really want is for Function A to call Function B via Invoke-WebRequest, but not wait for any sort of response. Not even a confirmation etc. How to do that though?

Enter Start-Job. Or in the case of Azure Functions, Start-ThreadJob.

I replaced the above code with the following:

Now Function A triggers the Invoke-WebRequest. It waits until it is running, and then it exists as before via the following:

That should do the trick I think. If not, you’ll find an update below when I learn more. :)