0

I've hosted a NodeJS webjob on a webapp that has 5 running instances. I'm triggering the webjob using the Kudu API

https://xyz.scm.azurewebsites.net/api/triggeredwebjobs/webjobname/run

The first request is accepted and webjob starts running but any subsequent request is giving error because the job is in running state.

HTTP 409 Cannot start a new run since job is already running.

I expect that I should be able trigger using the REST endpoint 5 times and another instance of webapp hosting the "free" job should pick it up. Is that not possible? Can you only trigger a single webjob despite of number of webapp instances you're running?

Increased scaling of App service plan to 5 instances and tried triggering the 'triggered webjob' with KUDU API Expectations : Should be able to submit 5 requests since the 'free instance' will handle the request Actual : First request is submitted with HTTP 202, any other request fails with 409 until the first webjob finishes running.

akum1143
  • 11
  • 1
  • The error indicates that you are trying to run the same job which is already in running state. – Harshitha May 18 '23 at 10:34
  • Yes, I'm aware that the job is running. My intention is to submit another request so that another instance of webapp(since I have multiple) can handle the new request. – akum1143 May 18 '23 at 10:37
  • May be the jobs are trying to access the same resource which is causing the error. – Harshitha May 18 '23 at 10:38
  • To test this, I kept only a Logging statement and reading Job Args in the function. It still throws 409. It shouldn't be a code issue related to resource sharing. It could be an Azure issue – akum1143 May 18 '23 at 10:40
  • AFAIK,this is the expected behaviour when running the jobs in KUDU api. – Harshitha May 18 '23 at 10:41
  • Is there any other way to trigger webjob in parallel? My usecase must have jobs running in parallel when triggered otherwise webjob is not a good fit – akum1143 May 18 '23 at 10:44
  • Instead of running the web job directly, try to use Azure Storage Queue. – Harshitha May 18 '23 at 10:45
  • Another alternative is to use Logic Apps. – Harshitha May 18 '23 at 10:47
  • Got it. I'll keep this question open for any other way to trigger in parallel/anyone can confirm that it's not possible. Thanks for the info, I'll look into those meanwhile! – akum1143 May 18 '23 at 10:50
  • Is your Job Continuous or triggered.If it is triggered try to run a continuous job and check whether it is allowing to run multiple instances. – Harshitha May 18 '23 at 10:52
  • Refer this [MSDoc](https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#multiple-instances) once. – Harshitha May 18 '23 at 10:57
  • It's a triggered job since I want to pass some params in the KUDU Api call, do some processing and stop. However if this doesn't work, I'll check continuous job, which can listen to a queue and process. I've gone through the documentation, it doesn't say any where that you can't manually trigger more instances. – akum1143 May 18 '23 at 11:04
  • Refer this [SOThread](https://stackoverflow.com/questions/44601938/run-many-instances-of-same-azure-webjob-concurrently-from-single-web-app) which explains the same. – Harshitha May 18 '23 at 11:06

1 Answers1

0

As mentioned in the MSdoc to run a WebJob on multiple instances use Continuous Job.

If your web app runs on multiple instances, a continuous WebJob runs on each instance, listening for triggers and calling functions.

  • We can see the same in the App Service as well, only continuous job has the multiple instance option.

Triggered Job: enter image description here

Continuous Job: Continuous Web Jobs can be scaled to run multiple instances.

enter image description here

Using KUDU API:

enter image description here

Increased scaling of App service plan to 5 instances and tried triggering the 'triggered webjob' with KUDU API Expectations :

As triggered jobs run only in single instance scaling up of the App Service plan does not make any changes.

Also refer the SOThreads 1 and 2 which explains running multiple instances of Web Jobs at once.

Harshitha
  • 3,784
  • 2
  • 4
  • 9