Skip to content

Commit

Permalink
Allow to trigger a finish hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dei79 committed Nov 10, 2023
1 parent 4565a90 commit f978534
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backup.runner/Manifest/ManifestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public class ManifestItem
public string SourcePath { get; set; } = string.Empty;

public List<string> Excludes { get; set; } = new List<string>();

public string FinishedHook { get; set; } = string.Empty;
}
19 changes: 16 additions & 3 deletions backup.runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@
continue;
}

// execute the operation
logger.LogInformation($"Processing task {manifestItem.Name} ({manifestItem.Id}) - {manifestItem.Operation} {manifestItem.Storage}");

if (manifestItem.Operation == OperationType.Backup && manifestItem.Storage == StorageType.Table)
{
// backup
await TableBackupClient.BackupAsync(manifestItem, loggerFactory);
else if (manifestItem.Operation == OperationType.Restore && manifestItem.Storage == StorageType.Table)

// trigger the finished hook if needed
if (!String.IsNullOrEmpty(manifestItem.FinishedHook))
await HookTrigger.TriggerHookAsync(manifestItem.FinishedHook);

} else if (manifestItem.Operation == OperationType.Restore && manifestItem.Storage == StorageType.Table)
{
await TableBackupClient.RestoreAsync(manifestItem, loggerFactory);
}
else
{
throw new InvalidOperationException(
$"Operation {manifestItem.Operation} or storage {manifestItem.Storage} is not supported");
$"Operation {manifestItem.Operation} or storage {manifestItem.Storage} is not supported");
}


}
18 changes: 18 additions & 0 deletions backup.runner/Services/HookTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using backup.runner.Manifest;
using Newtonsoft.Json;

namespace backup.runner.Services;

internal static class HookTrigger
{
public static async Task TriggerHookAsync(string hook)
{
var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(hook);
if (!response.IsSuccessStatusCode)
throw new InvalidOperationException($"Failed to trigger finished hook {response.ReasonPhrase}");
}
}

0 comments on commit f978534

Please sign in to comment.