-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathSubscription.workflow.cs
More file actions
33 lines (30 loc) · 1021 Bytes
/
Subscription.workflow.cs
File metadata and controls
33 lines (30 loc) · 1021 Bytes
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
namespace TemporalioSamples.Timer;
using Microsoft.Extensions.Logging;
using Temporalio.Exceptions;
using Temporalio.Workflows;
[Workflow]
public class Subscription
{
[WorkflowRun]
public async Task RunAsync(string userId)
{
try
{
while (true)
{
await Workflow.DelayAsync(TimeSpan.FromDays(30));
var result = await Workflow.ExecuteActivityAsync(
() => MyActivities.Charge(userId),
new() { StartToCloseTimeout = TimeSpan.FromMinutes(5) });
Workflow.Logger.LogInformation("Activity result: {Result}", result);
}
}
catch (Exception e) when (TemporalException.IsCanceledException(e))
{
Workflow.Logger.LogInformation("Workflow cancelled, cleaning up...");
// Handle any cleanup here
// Re-throw to close the workflow as Cancelled. Otherwise, it will be closed as Completed.
throw;
}
}
}