3

Apparently there used to be a way to create custom timers for Azure Functions, by creating a class that inherits from TimerSchedule and defining the custom logic in its GetNextOccurrence method.

We've got an MSDN post about it,, we've got a StackOverflow answer about it, and even some official sample code that uses custom timers.

None of it works.

None of these samples have a FunctionName attribute on their functions, which is needed (in the current SDK version, at least; not sure how long this has been the case) to make the Azure Function job actually run. And in the current SDK, any function that has both a FunctionName and a TimerTrigger that uses a custom timer type will fail to build with an error like this:

System.NotImplementedException: Property 'ScheduleType' on attribute 'TimerTriggerAttribute' is not supported in Azure Functions.

Apparently this used to work, but it doesn't now, and I'm having a heck of a time finding any relevant information on what the correct way is to do it now. Does anyone know what the new way is to set up a custom timer?

2 Answers 2

2

This can't be done with timers directly. Queues might be the right choice here: The previous run would have to create a message and send it to the queue. Make sure that the message becomes visible only after a specified time.

An alternative is to use Durable Functions, in particular an "eternal orchestration". Check out the example in the official docs here, where a job gets kicked off after a specified amount of time after the previous one has finished.

Sign up to request clarification or add additional context in comments.

Comments

0

Those are all in relation to web jobs - Azure Functions are not web jobs.

Azure Webjobs vs Azure Functions : How to choose

That said Azure Functions do have similiar timer functionaility - it even uses web job Nuget packages.

Timer trigger for Azure Functions

The following example shows a C# function that is executed each time the minutes have a value divisible by five (eg if the function starts at 18:57:00, the next performance will be at 19:00:00):

[FunctionName("TimerTriggerCSharp")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)

4 Comments

This example is a cron expression. It's exactly what I'm trying to figure out how to not use, because the logic I need can't be expressed as a cron expression and requires a custom timer that can compute any arbitrary time.
@masonwheeler looked at using a TimeSpan instead? What are you trying to achieve?
I'm trying to achieve a programatically-derived schedule that is not fixed because the amount of time before the next iteration runs depends on the results of previous iterations. Anything with a fixed value, whether it be a TimeSpan or a cron expression, will not work.
(And before you respond with any specific details about how serverless works that would make that difficult to get right, yes, I'm aware of all of that. I still need arbitrary, programmatic schedule generation.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.