initial project commit

This commit is contained in:
Flaminel
2024-11-09 18:40:47 +02:00
parent 4a4f180874
commit 04961f6d04
21 changed files with 421 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
using Common.Configuration;
using Executable.Jobs;
using Infrastructure.Verticals.FrozenTorrent;
namespace Executable;
using Quartz;
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) =>
services
.AddLogging(builder => builder.AddConsole())
.AddHttpClient()
.AddConfiguration(configuration)
.AddServices()
.AddQuartzServices(configuration);
private static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration) =>
services
.Configure<QuartzConfig>(configuration.GetSection(nameof(QuartzConfig)))
.Configure<SonarrConfig>(configuration.GetSection(nameof(SonarrConfig)));
private static IServiceCollection AddServices(this IServiceCollection services) =>
services
.AddTransient<FrozenTorrentHandler>();
private static IServiceCollection AddQuartzServices(this IServiceCollection services, IConfiguration configuration) =>
services
.AddQuartz(q =>
{
QuartzConfig? config = configuration.GetRequiredSection(nameof(QuartzConfig)).Get<QuartzConfig>();
if (config is null)
{
throw new NullReferenceException("Quartz configuration is null");
}
q.AddFrozenTorrentJob(config.FrozenTorrentTrigger);
})
.AddQuartzHostedService(opt =>
{
opt.WaitForJobsToComplete = true;
});
private static void AddFrozenTorrentJob(this IServiceCollectionQuartzConfigurator q, string trigger)
{
q.AddJob<FrozenTorrentJob>(opts =>
{
opts.WithIdentity(nameof(FrozenTorrentJob));
});
q.AddTrigger(opts =>
{
opts.ForJob(nameof(FrozenTorrentJob))
.WithIdentity($"{nameof(FrozenTorrentJob)}-trigger")
.WithCronSchedule(trigger);
});
}
}
+22
View File
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Executable-6108b2ba-f035-47bc-addf-aaf5e20da4b8</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-rc.1.24431.7"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Quartz" Version="3.13.1" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.13.1" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
</Project>
+29
View File
@@ -0,0 +1,29 @@
using Infrastructure.Verticals.FrozenTorrent;
using Quartz;
namespace Executable.Jobs;
[DisallowConcurrentExecution]
public sealed class FrozenTorrentJob : IJob
{
private ILogger<FrozenTorrentJob> _logger;
private FrozenTorrentHandler _handler;
public FrozenTorrentJob(ILogger<FrozenTorrentJob> logger, FrozenTorrentHandler handler)
{
_logger = logger;
_handler = handler;
}
public async Task Execute(IJobExecutionContext context)
{
try
{
await _handler.HandleAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, $"{nameof(FrozenTorrentJob)} failed");
}
}
}
+9
View File
@@ -0,0 +1,9 @@
using Executable;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddInfrastructure(builder.Configuration);
var host = builder.Build();
host.Run();
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Warning",
"Quartz": "Warning"
}
},
"QuartzConfig": {
"FrozenTorrentTrigger": "0 0/5 * * * ?"
},
"QBitConfig": {
"Url": "http://localhost:8080",
"Username": "",
"Password": ""
},
"SonarrConfig": [
{
"Url": "http://localhost:8989",
"ApiKey": ""
}
]
}