Skip to content

Commit

Permalink
Added delay
Browse files Browse the repository at this point in the history
  • Loading branch information
lyze237 committed May 6, 2024
1 parent 27f07ec commit cf45ddd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 11 additions & 3 deletions Jobs/BackupJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ public async Task Execute(IJobExecutionContext context) =>

private async Task Run(CancellationToken stoppingToken)
{
logger.LogInformation("Running worker");
await httpClient.GetAsync($"{proxmoxOptions.CronitorUrl}?state=run&host={Dns.GetHostName()}", stoppingToken);
var delay = Random.Shared.Next(1000, 10000);
logger.LogInformation("Running worker in {Ms} ms", delay);
await Task.Delay(delay, stoppingToken);

var startUrl = $"{proxmoxOptions.CronitorUrl}?state=run&host={Dns.GetHostName()}";
logger.LogInformation("Calling url {Url}", startUrl);
await httpClient.GetAsync(startUrl, stoppingToken);

var containers = await dockerClient.Containers.ListContainersAsync(new ContainersListParameters(), stoppingToken);

Expand All @@ -53,7 +58,10 @@ private async Task Run(CancellationToken stoppingToken)
uploadExitCode = await UploadToProxmox(allDirectories.ToArray());
}

await httpClient.GetAsync($"{proxmoxOptions.CronitorUrl}?state={(errorCounts == 0 && uploadExitCode == 0 ? "complete" : "fail")}&host={Dns.GetHostName()}&metric=error_count:{errorCounts}&status_code={uploadExitCode}&metric=count:{allDirectories.Count}{(allDirectories.Count == 0 ? "&message=NoUploads" : "")}", stoppingToken);
var finishUrl = $"{proxmoxOptions.CronitorUrl}?state={(errorCounts == 0 && uploadExitCode == 0 ? "complete" : "fail")}&host={Dns.GetHostName()}&metric=error_count:{errorCounts}&status_code={uploadExitCode}&metric=count:{allDirectories.Count}{(allDirectories.Count == 0 ? "&message=NoUploads" : "")}";
logger.LogInformation("Calling url {Url}", finishUrl);

await httpClient.GetAsync(finishUrl, stoppingToken);
}

private async Task<List<(string, string)>> DoContainerBackups(IList<ContainerListResponse> containers,
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/lib/docker/volumes:/mnt/var/lib/docker/volumes:ro
- type: tmpfs
target: /tmp
tmpfs:
mode: 01777
environment:
Proxmox__PasswordFile: "/run/secrets/proxmox_password_secret"
Proxmox__Repository: "bdd@pbs@backups.chirps.cafe:backups"
Proxmox__Namespace: "files"
Proxmox__Cronjob: "0 0 3 * * ?" # https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontrigger.html
Proxmox__CronitorUrl: https://cronitor.link/p/...

PostgresExample:
image: postgres
environment:
Expand Down

0 comments on commit cf45ddd

Please sign in to comment.