-
Notifications
You must be signed in to change notification settings - Fork 13
/
PurgeHistoryForMany.cs
39 lines (35 loc) · 1.47 KB
/
PurgeHistoryForMany.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DurableTask.Core;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
namespace DurableFunctions.Demo.DotNetCore._02_Maintenance
{
public class PurgeHistoryForMany
{
// https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#ncrontab-expressions
// https://cronexpressiondescriptor.azurewebsites.net
// {second} {minute} {hour} {day} {month} {day-of-week}
const string EveryDayAt730AM = "0 30 7 * * *";
[FunctionName(nameof(PurgeHistoryForMany))]
public async Task Run(
[TimerTrigger(EveryDayAt730AM)]TimerInfo myTimer,
[DurableClient] IDurableClient client,
ILogger log)
{
var instancesCreatedFromDate = DateTime.Today.Subtract(TimeSpan.FromDays(14));
var instancesCreatedToDate = DateTime.Today.Subtract(TimeSpan.FromDays(7));
var statussesToPurge = new List<OrchestrationStatus> {
OrchestrationStatus.Completed,
OrchestrationStatus.Terminated,
};
var purgeResult = await client.PurgeInstanceHistoryAsync(
instancesCreatedFromDate,
instancesCreatedToDate,
statussesToPurge);
log.LogInformation($"Purged {purgeResult.InstancesDeleted} instances.");
}
}
}