I will start explaining what i'm trying to do and then what problem i'm facing. So i have a leaderboard where every day you have a winner, but if you've won in the last month you can't win again (your score is still shown in the leaderboard) and the price goes to the next in line. So I made a function in Azure that does the following:
Grabs the current leaderboard
Reset the leadearboard (it runs at the same time as the next step)
Check the user internal data to check if he won in the last 30 days, if not moves to the next player in the leaderboard until we have someone who hasn't win in the last month.
Gives the price to the winner
Now the only problem i'm facing is that sometimes (not always) it runs out of time and the function is shown as failed. Sometimes it takes around 1600ms, others 3000ms and sometimes it fails because of the 4500ms Limit. Something i want to point out, the max number of players we need to check is 31, so we are running this with the same number of players everytime. Also we end the player check as soon as a winner is found and we are testing this with the number 31 being the winner (Just to make sure that it can support the max number without failing). If we run this without Scheduled Tasks it works 100% of the times. The problem is we need to run this in Scheduled Tasks Here you can see that sometimes it works and sometimes it doesn't