0

I've been looking around for a solution to an issue I am having. I looked at various posts on the same topic but none of them solved my issue, hence creating a new thread for this, so kindly read it once before marking it as duplicate.

I've created a C# HTTP Timer Trigger Function on Azure and specified CRON timing, but it is behaving weirdly.

This is my function.js

X

My cron expression: 0 */60 15-3 * * 1,2,3,4,5,6

My function will trigger every 60 minutes between 03:00 PM and 03:00 AM, only on Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday

But to my surprise it is triggering from 3:00 AM to 3:00 PM, and I am unable to understand why.

I followed the accepted answer of Azure function is not triggering on scheduled time post but still it is behaving the same.

Note: I have not enabled internal logging but I am maintaining a separate log in a different folder on Azure.

Edit 1: I just noticed that, if my function has been scheduled to run within the day i.e. if hour has been set anywhere between 0-24, it works properly but if hour has been set in such a way that it goes over the day i.e. 15-3 (in my case) its behavior changes completely and it runs from 3-15 and not the other way around.

James Z
  • 12,209
  • 10
  • 24
  • 44
Sohail
  • 43
  • 1
  • 12

1 Answers1

0

*/60make non sense. Use 0 And following cron logic make two records like:

0 0 0-3 * * 1,2,3,4,5,6
0 0 15-23 * * 1,2,3,4,5,6

If you want to make them as only one record you can try this:

0 0 0-3,15-23 * * 1,2,3,4,5,6

If this do not work you should use record like:

0 0 0,1,2,3,15,16,17,18,19,20,21,22,23 * * 1,2,3,4,5,6
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • The reason of using */60 in minutes is because that value is taken from the user and can only be entered as follows /2, /3, /4, /5, /6, /10, /12, /15, /20, /30 and /60. Hence */60, but it has not given me any problem if the hour is set between 0-24, since this particular function has been set to 15-3 , it is causing me problem. I'd like to know what do you mean by "And following cron login make two records like". From where can I do that? I tried to use your given expression in function.json but it isn't allowing me to do so. – Sohail Feb 26 '19 at 14:23
  • @Sohail, its mistake, I mean logic :) – Romeo Ninov Feb 26 '19 at 14:39
  • And make your script on such way it start two, not one schedule record – Romeo Ninov Feb 26 '19 at 14:39
  • I am making these functions on Azure and since it consumes resources and money, I cannot make 2 functions to perform same functionality. And also these functions are created programmatically/dynamically through code, and depending upon the action, each person gets only 1 function, so not a feasible option to create 2 functions for performing same task. Any other way I can do to make my function run in the given cron expression (hour would be set as 15-3) – Sohail Feb 26 '19 at 15:25
  • 1
    this worked for me. I tried both your options and it works like a charm. Thank you. :) – Sohail Feb 28 '19 at 05:00
  • I had one more doubt.. In one of my Azure Functions, I've specified the cron as 0 */120 * * * 1,2,3,4,5 . And checked my cron description over here https://cronexpressiondescriptor.azurewebsites.net/ . It says "Every 120 minutes, only on Monday, Tuesday, Wednesday, Thursday, and Friday" but this is not the case. I thought it would trigger after every 120 mins but it is triggering every hour. Also I changed the cron from */120 to */50 and strangely it is triggering at 3:00pm, 3:50pm, 4:00pm. I thought it would run after every 50 mins.. – Sohail Mar 18 '19 at 13:31
  • @Sohail, to make it run every 120 minutes you can use record like: `* * */2 * *......` (divide hours by 2). FOr 50 minutes you need more than one cron record to do it – Romeo Ninov Mar 18 '19 at 15:38
  • Is it possible to use */50 in single cron record instead of two? Like your above answer where you told me to split my time into two comma separated, is it possible to do something similar? Example 0 */50 0-3,15-23 * * 1,2,3,4,5,6 I want to use this cron, but minutes should be */50 – Sohail Mar 19 '19 at 10:30
  • @Sohail, this will run cron every 0 and 50 minute each hour. If you want to run it every 50 minutes will be much more complicated (and more than one record) – Romeo Ninov Mar 19 '19 at 10:40