-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopACIs.cs
28 lines (25 loc) · 879 Bytes
/
StopACIs.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
using System.Threading.Tasks;
using Microsoft.Azure.Management.ContainerInstance.Fluent;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace AzureScheduler
{
public static class StopACIs
{
[FunctionName("StopACIs")]
public static async Task Run([TimerTrigger("0 0 22 * * *")]TimerInfo myTimer, ILogger log)
{
var azure = Configuration.GetAzureApi();
var acis = await azure.ContainerGroups.ListAsync();
await ResourceHelper.ProcessResources(
acis,
aci => aci.State == "Running",
aci => Stop(aci, log), log );
}
public static Task Stop(IContainerGroup containerGroup, ILogger log)
{
log.LogInformation("Stopping " + containerGroup.Name);
return containerGroup.StopAsync();
}
}
}