We have to write multiple triggers. I was hoping to create separate functions, based on the trigger types. So if I need 5 timer triggers, that will run at different times, I would create one Timer trigger function class and name the functions like [TimerTrigger1]
, [TimerTrigger2]
, [TimerTrigger3]
... and so forth. After I added the code I am not sure if I can do that anymore.
Can someone suggest how I can go about adding multiple triggers? I can't have two Run
functions under one class.
public static class TimerTrigger
{
[FunctionName("InsertTimerTrigger1")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
// Do task 1
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
[FunctionName("InsertTimerTrigger2")]
public static void Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, ILogger log)
{
//Do Task 2
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
You can create multiple functions in Single Class. You can change Run
Method name.
public static class Function1
{
[FunctionName("Function1")]
public static void Method1([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
[FunctionName("Function2")]
public static void Method2([TimerTrigger("0 */3 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
But I will recommend, Create multiple functions will help you (5 in your case).
You can choose any name for the methods. (Naming it as "Run" is not a requirement.)
public static class TimerTrigger
{
[FunctionName("InsertTimerTrigger1")]
public static void InsertTimerTrigger1([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
// Do task 1
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
[FunctionName("InsertTimerTrigger2")]
public static void InsertTimerTrigger2([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, ILogger log)
{
//Do Task 2
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With