-
Notifications
You must be signed in to change notification settings - Fork 3
/
SlackCronJobs.cs
73 lines (66 loc) · 2.53 KB
/
SlackCronJobs.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
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace Nysgjerrig
{
public class SlackCronJobs
{
private readonly string _queryNextUrl;
private readonly string _queryFollowupUrl;
public SlackCronJobs()
{
_queryNextUrl = Environment.GetEnvironmentVariable("QueryNextEndpoint");
_queryFollowupUrl = Environment.GetEnvironmentVariable("QueryFollowupEndpoint");
if (string.IsNullOrWhiteSpace(_queryNextUrl)) throw new ArgumentException("***QueryNextEndpoint not set***");
if (string.IsNullOrWhiteSpace(_queryFollowupUrl)) throw new ArgumentException("***QueryFollowupEndpoint not set***");
}
[FunctionName("TriggerNext")]
public async Task TriggerNext([TimerTrigger("0 0 11 * * 1-5")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"{nameof(TriggerNext)} fired: {DateTime.Now}");
try
{
using var client = new HttpClient();
var response = await client.GetAsync(_queryNextUrl);
if (response.IsSuccessStatusCode)
{
log.LogInformation($"{nameof(TriggerNext)} OK {await response.Content.ReadAsStringAsync()}");
}
else
{
log.LogWarning($"{nameof(TriggerNext)} FAILED {response.ReasonPhrase}");
}
}
catch (Exception ex)
{
log.LogError(ex.Message, ex);
throw;
}
}
[FunctionName("TriggerFollowup")]
public async Task TriggerFollowup([TimerTrigger("0 15 11 * * 1-5")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"{nameof(TriggerFollowup)} fired: {DateTime.Now}");
try
{
using var client = new HttpClient();
var response = await client.GetAsync(_queryFollowupUrl);
if (response.IsSuccessStatusCode)
{
log.LogInformation($"{nameof(TriggerFollowup)} OK {await response.Content.ReadAsStringAsync()}");
}
else
{
log.LogWarning($"{nameof(TriggerFollowup)} FAILED {response.ReasonPhrase}");
}
}
catch (Exception ex)
{
log.LogError(ex.Message, ex);
throw;
}
}
}
}