1
votes

I am using the Azure Scheduler REST API, and I am having a hard time updating one job recurrence from weekly/monthly to hourly. Specifically I get the following error: Schedules are not supported for recurrence unit 'Hour'.

The problem is that the specific job used to have some advanced scheduling options, which of course I do not need if I want to update to hourly frequency. According to the MSDN Documentation if you do not include one field (in this case 'schedule'), the current value will be carried over. I have tried not including the schedule field at all, including it with null value, including it with empty object or with all properties (hours, minutes etc.) set to null and in all cases I got a HTTP Bad Request with the error message above.

Here's my job as returned by a get operation:

 {
   "id":"************",
   "type":"Microsoft.Scheduler/jobCollections/jobs",
   "name":"my-job-collection/my-job-id",
   "properties":{
      "startTime":"2016-03-01T00:00:00Z",
      "action":{ /*....*/ },
      "recurrence":{
         "frequency":"week",
         "interval":4,
         "schedule":{
            "minutes":[ 0 ],
            "hours":[ 12 ],
            "weekDays":[ "saturday" ]
         }
      },
      "state":"enabled",
      "status":{ /*....*/ }
   }

And here is the patch I am trying to submit:

{
   "properties":{
      "recurrence":{
         "frequency":"hour"
      }
   }
}
/* or */
{
   "properties":{
      "recurrence":{
         "frequency":"hour",
         "schedule": null
      }
   }
}

The API version I am using is 2016-01-01.

Any help would be appreciated. Thank you

1
Did you try to set the frequency to be minute, and interval to be 60? e.g. "recurrence": {"frequency": "minute","interval": 60}Jack Zeng
If you want to change the recurrence unit, you must include the "interval".Jack Zeng
@JackZeng minute doesn't work either, as well as including interval. I can update recurrence to month or year without including interval. The idea is that if a field is not specified the current value is carried over, the problem with hour and minute is that the old (weekly) "schedule" value is carried over - and then it complains you can have schedule with hour or minute recurrence unit.ovidiu
I see the issue. You need to use "hours" instead of "hour", and "minutes" instead of "minute".Jack Zeng
It's weird that both "week" and "weeks" work, but "hour" doesn't work while "hours" does.Jack Zeng

1 Answers

0
votes

I have been trying to reproduce your issue, and I have found the following issue.

I call the REST API with the following input:

{
    "properties": {
        "recurrence": {
            "frequency":"week",
            "schedule":{
               "minutes":[ 0 ],
               "hours":[ 12 ],
               "weekDays":[ "saturday" ]
            }
        }
    }
}

No problem with this step. After this, I call the REST API on this input:

{
    "properties": {
        "recurrence": {
            "frequency":"hour"
        }
    }
}

Now, I get the error:

enter image description here

Here is the reason for this issue. You have set the schedule to been on Saturday, which is only meaningful for weekly schedule.

It's strange that they will automatically remove the advanced schedule when changing recurrence unit in the portal, while through REST API, they don't do that for you. I will report this issue to Microsoft. Hopefully, they will fix this in the future release.

Here is the solution. Log into the new portal, and change the recurrence unit once, after that, you would be able to update the unit through REST API again.

Or, use "PUT" instead of "PATCH" method for your REST API.

For the "PUT" REST API, you need to use the whole JSON from the "GET" REST API, but deleting the "schedule" setting in the "properties". For example:

{
   "id":"************",
   "type":"Microsoft.Scheduler/jobCollections/jobs",
   "name":"my-job-collection/my-job-id",
   "properties":{
       "startTime":"2016-03-01T00:00:00Z",
       "action":{ /*....*/ },
       "recurrence":{
           "frequency":"hour",
           "interval":4
       },
       "state":"enabled",
       "status":{ /*....*/ }
   }
}