Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from LuccaSA/fix-download-dependencies
Browse files Browse the repository at this point in the history
Fix download of dependencies
  • Loading branch information
seguins authored Jun 8, 2022
2 parents 85e4edd + 309aa09 commit 87159d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 0 additions & 6 deletions TCC/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Hosting;
using System.CommandLine.Parsing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using TCC.Lib;
using TCC.Lib.Helpers;
using TCC.Lib.Options;
using TCC.Parser;

namespace TCC
Expand Down
21 changes: 18 additions & 3 deletions TCC/TccController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using TCC.Lib;
using TCC.Lib.Benchmark;
using TCC.Lib.Database;
using TCC.Lib.Dependencies;
using TCC.Lib.Helpers;
using TCC.Lib.Notification;
using TCC.Lib.Options;
Expand All @@ -35,29 +36,35 @@ public class TccController : ITccController
private readonly DatabaseSetup _databaseSetup;
private readonly BenchmarkRunner _benchmarkRunner;
private readonly SlackSender _slackSender;
private readonly ExternalDependencies _externalDependencies;
private readonly CancellationTokenSource _cancellationTokenSource;

public TccController(
ILogger<TccController> loger, TarCompressCrypt tarCompressCrypt,
DatabaseSetup databaseSetup, BenchmarkRunner benchmarkRunner,
SlackSender slackSender)
SlackSender slackSender, ExternalDependencies externalDependencies,
CancellationTokenSource cancellationTokenSource)
{
_logger = loger;
_tarCompressCrypt = tarCompressCrypt;
_databaseSetup = databaseSetup;
_benchmarkRunner = benchmarkRunner;
_slackSender = slackSender;

_externalDependencies = externalDependencies;
_cancellationTokenSource = cancellationTokenSource;
_logger.LogInformation($"Starting ------------------------------------------------- {DateTime.UtcNow}");
}

public async Task CompressAsync(CompressOption option)
{
await InitTccAsync();
var operationResult = await _tarCompressCrypt.CompressAsync(option);
await LogResultAsync(operationResult, Mode.Compress, option);
}

public async Task DecompressAsync(DecompressOption option)
{
await InitTccAsync();
await _databaseSetup.EnsureDatabaseExistsAsync(Mode.Decompress);
var operationResult = await _tarCompressCrypt.DecompressAsync(option);
await _databaseSetup.CleanupDatabaseAsync(Mode.Decompress);
Expand All @@ -66,12 +73,14 @@ public async Task DecompressAsync(DecompressOption option)

public async Task BenchmarkAsync(BenchmarkOption option)
{
await InitTccAsync();
var operationResult = await _benchmarkRunner.RunBenchmarkAsync(option);
await LogResultAsync(operationResult, Mode.Benchmark, null);
}

public async Task AutoDecompressAsync(AutoDecompressOptionBinding option)
{
await InitTccAsync();
var gcpCredential = await GoogleAuthHelper.GetGoogleClientAsync(option.GoogleStorageCredential, new CancellationToken());
var subscriber = await GetGoogleClientAsync(gcpCredential, option);
var storage = await StorageClient.CreateAsync(gcpCredential);
Expand Down Expand Up @@ -215,4 +224,10 @@ private void WriteAuditFile(Mode mode, OperationSummary op)
}
}
}
}

private Task InitTccAsync()
{
_cancellationTokenSource.HookTermination();
return _externalDependencies.EnsureAllDependenciesPresent();
}
}

0 comments on commit 87159d4

Please sign in to comment.