title: Terminate durable function
body: <p>I wrote a durable function in order to scale data queries to some API internal to our organization. The orchestration function spreads queries across activity functions only two of which will be active at once (in order not to flood the server).</p>
  <p>A colleague accidentally created a few instances of the durable function which would create roughly 70 activity functions. Because the output is not needed at this point, I want to terminate both the orchestration and all running and pending activity functions.</p>
  <p>In PowerShell, using the <a href="https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-api#get-all-instances-status" rel="nofollow noreferrer">HTTP APIs</a>, I queried the id's of all pending and running instances of the durable function on this function app</p>
  <pre><code>Invoke-RestMethod -Uri &quot;https://{fapp}.azurewebsites.net/runtime/webhooks/durableTask/instances?taskHub=$taskHub&amp;connection=$connectionName&amp;code=$systemKey&amp;createdTimeFrom=$timestampFrom&amp;createdTimeTo=$timestampTo&amp;runtimeStatus=Pending,Running&quot;
  </code></pre>
  <p>and terminated each one manually</p>
  <pre><code>Invoke-RestMethod -Uri &quot;https://{fapp}.azurewebsites.net/runtime/webhooks/durabletask/instances/$instanceId/terminate?reason=$reason&amp;taskHub=$taskhub&amp;connection=$connectionName&amp;code=$systemKey&quot; -Method &quot;Post&quot;
  </code></pre>
  <p>As expected, executing the first query again no longer returns any information as no instances should be pending and running at this point. Also, the returned object when filtering on <code>runtimeStatus=Terminated</code> confirms that my queries were successful.</p>
  <p>However, I still see the output generated from the functions (in my case, files are generated in a blob storage container). Hoping that I had deleted all pending activity functions but not currently running ones, I waited for the output worth of one activity function to be generated. However, this amount was exceeded which is why it seems that new activity functions are started.</p>
  <p>Questions:</p>
  <ul>
  <li>Why are there still queued and/or running activity functions?</li>
  <li>How can I identify their instance id's and terminate them?</li>
  <li>The easiest option would be to terminate all queued and running instances for this function app. Is that possible? How?</li>
  </ul>
  <p>Note: The function app is currently turned off to identify a solution.</p>