ishahrier
ishahrier

Reputation: 109

Stop azure function programmatically

Hi I understand that if I create an azure function , which is triggered by a msg in a queue, can scale out (horizontally) if there are multiple messages in the queue.In other words, multiple instances of the same azure function can be running to process the msgs in the queue.

I also know that in an azure function I can get the ID of the running instance. Lets assume when an instance of my azure function starts I store the ID of the running instance in a database.

Now, my question is, how can I stop/kill a specific instance (identified by the stored ID) of my azure function programmatically?

THANKS IN ADVANCE!!

THE SCENARIO

I have a dashboard for my users. Where they can create a task.Once the task is created the definition goes to the queue along with user id as a msg. And as soon as the msg is available in the queue the azure function gets triggered. Now when the user refreshes the dashboard she/he sees the list of tasks (created by him/her) whether they are running or done. I am now required to give them an option to stop a running task as well.

Now multiple users can create the tasks with different params sending multiple msgs in the same queue which will result in running multiple instances of the same azure function. Each instances are tied with specific user. And if the user chooses to stop a task (which is the instance of that same azure function) I need to stop that specific instance of the azure function (not same as disabling the entire azure function).Now all i know about a running instance is the ID , and I was wondering if I can stop/kill/cancel that specific function instance from code.

I hope i successfully explained my situation. if you have more questions please let me know.

Upvotes: 4

Views: 4339

Answers (1)

brettsam
brettsam

Reputation: 2792

There's no way to do this today. Even if you were to kill an instance, the Functions Scale Controller would likely see that you need more instances for processing and start another for you anyway.

It'd be good to fully understand the scenario here -- are you trying to limit scale-out? Or stop individual runaway functions?

Edit: After reading your scenario, have you looked at Durable Functions? You should be able to kick off orchestrations based on queue messages and manage them with an OrchestrationClient. The caveat is that Activity functions cannot be cancelled once they've been started, but if you decompose your steps enough you would be able to terminate an in-process orchestration. See here for more details:

Upvotes: 1

Related Questions