-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventPub.cs
More file actions
61 lines (49 loc) · 2.17 KB
/
EventPub.cs
File metadata and controls
61 lines (49 loc) · 2.17 KB
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
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using System;
using System.Threading;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace gbelenky.EventPub
{
public static class EventPub
{
[FunctionName("EventScheduler")]
public static async Task EventScheduler(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
EventCalendar eventCalendar = context.GetInput<EventCalendar>();
// DateTime startTime = context.CurrentUtcDateTime;
DateTime startTime = eventCalendar.StartTime.UtcDateTime;
await context.CreateTimer(startTime, CancellationToken.None);
await context.CallActivityAsync<string>("EventWorker", eventCalendar.Name);
// or make a direct call context.CallHttpAsync without the Activity "EventWorker"
eventCalendar.SetNextStartTime();
// eternal execution
context.ContinueAsNew(eventCalendar);
return;
}
[FunctionName("EventWorker")]
public static string PublishEvent([ActivityTrigger] string name, ILogger log)
{
log.LogInformation($"___***Publishing Events for {name}.***___");
return $"Events for {name} were published";
}
[FunctionName("StartScheduler")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
string eventCalendarPayload = await req.Content.ReadAsStringAsync();
EventCalendar eventCalendar = JsonSerializer.Deserialize<EventCalendar>(eventCalendarPayload);
string instanceId = await starter.StartNewAsync("EventScheduler", eventCalendar);
log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
}
}