1

I have created a trigger web job for some web application call, but I got a requirement that trigger job customer should be able to start or stop when want, and can also schedule.

I have done the schedule part using webjobs rest API but I am not able to complete start and stop work as trigger job does not have any option.

Is there a way to start and stop trigger webjob. I have tried to use kudo kill process but after webjob trigger completes it does not appear in process explorer.

var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{azureUserName}:{azurePassword}"));

if (string.Equals(jobStatus, "STOP", StringComparison.InvariantCultureIgnoreCase)) 
{
  using(var client = new HttpClient()) 
  {
    client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
    
    //var baseUrl = new Uri($"https://{webAppName}.scm.azurewebsites.net/");
    var requestURl = string.Format("{0}/api/processes", azureWebAppUrl);
    
    var response = client.GetAsync(requestURl).Result;
    
    if (response.IsSuccessStatusCode == true) 
    {
      string res = response.Content.ReadAsStringAsync().Result;
      var processes = JsonConvert.DeserializeObject < List < ProcessData >> (res);
      
      if (processes.Any(x => x.name.Contains(azureWebJobName))) 
      {
        requestURl = string.Format("{0}/api/processes/{1}", azureWebAppUrl, processes.Where(x => x.name.Contains(azureWebJobName)).FirstOrDefault().id);
        response = client.DeleteAsync(requestURl).Result;
      }

      returnStr = "success";
    } 
    else 
    {
      returnStr = response.Content.ToString();
    }
  }
}

Please help me to understand a better way to stop and start the trigger web job process. I also found that we can add app settings to the main application like WEBJOBS_STOPPED and WEBJOBS_DISABLE_SCHEDULE but it will depend and need to update it every time, I want to rely on webjob setting completely instead of main application settings.

cdev
  • 5,043
  • 2
  • 33
  • 32
Sandy
  • 57
  • 1
  • 17
  • question is not clear to me!!! this link may help you.. https://stackoverflow.com/questions/31064071/how-to-prevent-azure-webjobs-from-being-swapped-in-azure-website-production – MD. RAKIB HASAN Nov 02 '21 at 12:26
  • I think that you are talking about the WebJob in Azure, right? In that case this one might be helpful: https://stackoverflow.com/questions/26636995/azure-stop-a-triggered-web-job – victor6510 Nov 04 '21 at 04:10
  • Hi victor, my web job is schedule job due to which i am not able to stop it by killing it by kudo api as code I mention above. Is there any other way to stop my web job using power shell command or any azure service through can i stop – Sandy Nov 18 '21 at 15:19

1 Answers1

0

I do not know if I understand your problem or not.

I think, You can use Quartz(1) for start job/jobs and schedule it with application setting.

https://www.quartz-scheduler.net/

  • Hi Sajad, my problem is to stop schedule web job from c# code which tried through kudu api for reference please see my above code, but due to schedule web job process does not come into process explorer. Is any other option available to stop schedule web job – Sandy Nov 18 '21 at 15:22