-
Notifications
You must be signed in to change notification settings - Fork 206
/
TimerSamples.cs
73 lines (63 loc) · 2.43 KB
/
TimerSamples.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Timers;
namespace WebJobsSandbox
{
public static class TimerSamples
{
/// <summary>
/// Example job triggered by a crontab schedule.
/// </summary>
public static void CronJob([TimerTrigger("*/15 * * * * *")] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired!");
}
/// <summary>
/// Example job triggered by an crontab schedule that is also configured
/// to run immediately on startup.
/// </summary>
public static void StartupJob([TimerTrigger("0 0 */2 * * *", RunOnStartup = true, UseMonitor = true)] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired!");
string scheduleStatus = string.Format("Status: Last='{0}', Next='{1}', IsPastDue={2}",
timerInfo.ScheduleStatus.Last, timerInfo.ScheduleStatus.Next, timerInfo.IsPastDue);
Console.WriteLine(scheduleStatus);
}
/// <summary>
/// Example job triggered by a timespan schedule.
/// </summary>
public static void TimerJob([TimerTrigger("01:00:00")] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired!");
}
/// <summary>
/// Example job triggered by a custom schedule.
/// </summary>
public static void WeeklyTimerJob([TimerTrigger(typeof(MyWeeklySchedule))] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired!");
}
public class MyWeeklySchedule : WeeklySchedule
{
public MyWeeklySchedule()
{
// Every Monday at 8 AM
Add(DayOfWeek.Monday, new TimeSpan(8, 0, 0));
// Twice on Wednesdays at 9:30 AM and 9:00 PM
Add(DayOfWeek.Wednesday, new TimeSpan(9, 30, 0));
Add(DayOfWeek.Wednesday, new TimeSpan(21, 30, 0));
// Every Friday at 10:00 AM
Add(DayOfWeek.Friday, new TimeSpan(10, 0, 0));
}
}
public class MyDailySchedule : DailySchedule
{
public MyDailySchedule()
: base("8:00:00", "12:00:00", "22:00:00")
{
}
}
}
}