Reputation: 60841
I want my Azure Function to look at an SFTP folder, and move new files to their parent folders.
My scaffolding looks like this.
public static class OnMoveFilesHttpTriggered
{
[FunctionName("OnMoveFilesHttpTriggered")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
How do we enforce that there will be one and only one instance of this function running at any given time?
Upvotes: 4
Views: 4684
Reputation: 17800
It's by design that TimerTrigger uses the Singleton feature of the WebJobs SDK to ensure that only a single instance of your triggered function is running at any given time. Hence we don't have to do anything else to enforce it.
Check the wiki for details.
When the JobHost starts up, for each of your TimerTrigger functions a blob lease (the Singleton Lock) is taken. This distrubuted lock ensures that only a single instance of your scheduled function is running at any time. If the blob for that function is not currently leased, the function will acquire the lease and start running on schedule immediately. If the blob lease cannot be acquired, it generally means that another instance of that function is running, so the function is not started in the current host.
Upvotes: 17