Skip to content

Commit 5ef12aa

Browse files
committed
PR updates and removed worker test projects using git command
1 parent b649800 commit 5ef12aa

24 files changed

+232
-462
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace KeeperData.Bridge.Worker.Configuration;
2+
3+
public class ScheduledJobConfiguration
4+
{
5+
public string JobType { get; set; } = string.Empty;
6+
public bool Enabled { get; set; }
7+
public string CronSchedule { get; set; } = string.Empty;
8+
}

src/KeeperData.Bridge.Worker/Jobs/DataProcessingOrchestratorJob.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using KeeperData.Bridge.Worker.Tasks;
2+
using Microsoft.Extensions.Logging;
3+
using Quartz;
4+
5+
namespace KeeperData.Bridge.Worker.Jobs;
6+
7+
[DisallowConcurrentExecution]
8+
public class ImportBulkFilesJob(
9+
ITaskProcessBulkFiles taskProcessBulkFiles,
10+
ILogger<ImportBulkFilesJob> logger) : IJob
11+
{
12+
public async Task Execute(IJobExecutionContext context)
13+
{
14+
logger.LogInformation("ImportBulkFilesJob started at {startTime}", DateTime.UtcNow);
15+
16+
try
17+
{
18+
await taskProcessBulkFiles.RunAsync(context.CancellationToken);
19+
20+
logger.LogInformation("ImportBulkFilesJob completed at {endTime}", DateTime.UtcNow);
21+
}
22+
catch (Exception ex)
23+
{
24+
logger.LogError(ex, "ImportBulkFilesJob failed.");
25+
throw;
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using KeeperData.Bridge.Worker.Tasks;
2+
using Microsoft.Extensions.Logging;
3+
using Quartz;
4+
5+
namespace KeeperData.Bridge.Worker.Jobs;
6+
7+
[DisallowConcurrentExecution]
8+
public class ImportDeltaFilesJob(
9+
ITaskProcessDeltaFiles taskProcessDeltaFiles,
10+
ILogger<ImportDeltaFilesJob> logger) : IJob
11+
{
12+
public async Task Execute(IJobExecutionContext context)
13+
{
14+
logger.LogInformation("ImportDeltaFilesJob started at {startTime}", DateTime.UtcNow);
15+
16+
try
17+
{
18+
await taskProcessDeltaFiles.RunAsync(context.CancellationToken);
19+
20+
logger.LogInformation("ImportDeltaFilesJob completed at {endTime}", DateTime.UtcNow);
21+
}
22+
catch (Exception ex)
23+
{
24+
logger.LogError(ex, "ImportDeltaFilesJob failed.");
25+
throw;
26+
}
27+
}
28+
}

src/KeeperData.Bridge.Worker/KeeperData.Bridge.Worker.csproj

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Nullable>enable</Nullable>
65
<ImplicitUsings>enable</ImplicitUsings>
7-
<UserSecretsId>dotnet-KeeperData.Bridge.Worker-9c9ceddd-667d-4132-9837-ed22f2601850</UserSecretsId>
8-
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
9-
<DockerfileContext>..\..</DockerfileContext>
6+
<Nullable>enable</Nullable>
107
</PropertyGroup>
118

129
<ItemGroup>
13-
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="9.0.0" />
14-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
15-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
1610
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.15.0" />
17-
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
18-
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
19-
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\KeeperData.Infrastructure\KeeperData.Infrastructure.csproj" />
2015
</ItemGroup>
2116
</Project>

src/KeeperData.Bridge.Worker/Properties/launchSettings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using KeeperData.Bridge.Worker.Configuration;
2+
using KeeperData.Bridge.Worker.Jobs;
3+
using KeeperData.Bridge.Worker.Tasks;
4+
using KeeperData.Bridge.Worker.Tasks.Implementations;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Quartz;
8+
using System.Diagnostics.CodeAnalysis;
9+
10+
namespace KeeperData.Bridge.Worker.Setup;
11+
12+
[ExcludeFromCodeCoverage]
13+
public static class ServiceCollectionExtensions
14+
{
15+
public static void AddBackgroundJobDependencies(this IServiceCollection services, IConfiguration configuration)
16+
{
17+
services
18+
.AddQuartz(configuration)
19+
.AddJobs()
20+
.AddTasks();
21+
}
22+
23+
private static IServiceCollection AddQuartz(this IServiceCollection services, IConfiguration configuration)
24+
{
25+
var scheduledJobConfiguration = configuration.GetRequiredSection("Quartz:Jobs").Get<List<ScheduledJobConfiguration>>() ?? [];
26+
27+
services.AddQuartz(q =>
28+
{
29+
var importBulkFilesConfig = scheduledJobConfiguration.FirstOrDefault(x => x.JobType == nameof(ImportBulkFilesJob));
30+
if (importBulkFilesConfig?.CronSchedule != null)
31+
{
32+
q.AddJob<ImportBulkFilesJob>(opts => opts.WithIdentity(importBulkFilesConfig.JobType));
33+
34+
q.AddTrigger(opts => opts
35+
.ForJob(importBulkFilesConfig.JobType)
36+
.WithIdentity($"{importBulkFilesConfig.JobType}-trigger")
37+
.WithCronSchedule(importBulkFilesConfig.CronSchedule));
38+
}
39+
40+
var importDeltaFilesConfig = scheduledJobConfiguration.FirstOrDefault(x => x.JobType == nameof(ImportDeltaFilesJob));
41+
if (importDeltaFilesConfig?.CronSchedule != null)
42+
{
43+
q.AddJob<ImportDeltaFilesJob>(opts => opts.WithIdentity(importDeltaFilesConfig.JobType));
44+
45+
q.AddTrigger(opts => opts
46+
.ForJob(importDeltaFilesConfig.JobType)
47+
.WithIdentity($"{importDeltaFilesConfig.JobType}-trigger")
48+
.WithCronSchedule(importDeltaFilesConfig.CronSchedule));
49+
}
50+
});
51+
52+
services.AddQuartzHostedService(q =>
53+
{
54+
q.WaitForJobsToComplete = false;
55+
});
56+
57+
return services;
58+
}
59+
60+
private static IServiceCollection AddJobs(this IServiceCollection services)
61+
{
62+
services.AddScoped<ImportBulkFilesJob>();
63+
services.AddScoped<ImportDeltaFilesJob>();
64+
65+
return services;
66+
}
67+
68+
private static IServiceCollection AddTasks(this IServiceCollection services)
69+
{
70+
services.AddScoped<ITaskProcessBulkFiles, TaskProcessBulkFiles>();
71+
services.AddScoped<ITaskProcessDeltaFiles, TaskProcessDeltaFiles>();
72+
73+
return services;
74+
}
75+
}
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
namespace KeeperData.Bridge.Worker.Tasks;
62

7-
namespace KeeperData.Bridge.Worker.Tasks
3+
public interface ITask
84
{
9-
public interface ITask
10-
{
11-
Task RunAsync(CancellationToken cancellationToken);
12-
}
13-
}
5+
Task RunAsync(CancellationToken cancellationToken);
6+
}

src/KeeperData.Bridge.Worker/Tasks/ITaskDownload.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/KeeperData.Bridge.Worker/Tasks/ITaskProcess.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)