From 7c33b3f334cf91918add7af08866f2ea37ed9c3f Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Thu, 3 Sep 2026 23:06:05 +1000 Subject: chore: initial commit --- src/marlin.web/Services/DatabaseUpgrader.cs | 45 +++++++++++++++++++ src/marlin.web/Services/JobService.cs | 6 +++ .../Services/VersionControlSyncService.cs | 50 ++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/marlin.web/Services/DatabaseUpgrader.cs create mode 100644 src/marlin.web/Services/JobService.cs create mode 100644 src/marlin.web/Services/VersionControlSyncService.cs (limited to 'src/marlin.web/Services') diff --git a/src/marlin.web/Services/DatabaseUpgrader.cs b/src/marlin.web/Services/DatabaseUpgrader.cs new file mode 100644 index 0000000..6bb8bac --- /dev/null +++ b/src/marlin.web/Services/DatabaseUpgrader.cs @@ -0,0 +1,45 @@ +namespace marlin.web.Services; + +using Data; +using Microsoft.EntityFrameworkCore; + +public class DatabaseUpgrader : IHostedService +{ + private readonly ILogger _logger; + private readonly IServiceProvider _serviceProvider; + + public DatabaseUpgrader(ILogger logger, IServiceProvider serviceProvider) + { + this._logger = logger; + this._serviceProvider = serviceProvider; + } + + public async Task StartAsync(CancellationToken ct) + { + await using AsyncServiceScope scope = this._serviceProvider.CreateAsyncScope(); + DbContext dbContext = scope.ServiceProvider.GetRequiredService(); + + var migrations = await dbContext.Database.GetPendingMigrationsAsync(ct); + int pendingCount = migrations.Count(); + + if (pendingCount == 0) + { + this._logger.LogInformation("Database is up to date."); + return; + } + + this._logger.LogInformation("Upgrading database {count} versions.", pendingCount); + + try + { + await dbContext.Database.MigrateAsync(ct); + this._logger.LogInformation("Database upgraded."); + } + catch (Exception ex) + { + this._logger.LogError(ex, "Database upgrade failed, {count} behind.", pendingCount); + } + } + + public Task StopAsync(CancellationToken ct) => Task.CompletedTask; +} \ No newline at end of file diff --git a/src/marlin.web/Services/JobService.cs b/src/marlin.web/Services/JobService.cs new file mode 100644 index 0000000..ec187c1 --- /dev/null +++ b/src/marlin.web/Services/JobService.cs @@ -0,0 +1,6 @@ +namespace marlin.web.Services; + +public class JobService +{ + +} \ No newline at end of file diff --git a/src/marlin.web/Services/VersionControlSyncService.cs b/src/marlin.web/Services/VersionControlSyncService.cs new file mode 100644 index 0000000..ba40662 --- /dev/null +++ b/src/marlin.web/Services/VersionControlSyncService.cs @@ -0,0 +1,50 @@ +namespace marlin.web.Services; + +using System.Diagnostics; +using System.Text; +using core.functional; +using core.models; +using Data; +using Microsoft.EntityFrameworkCore; + +public class VersionControlSyncService : BackgroundService +{ + private readonly ILogger _logger; + private readonly IServiceProvider _services; + + private ICollection _sources; + private Dictionary _nextPoll; + + public VersionControlSyncService(ILogger logger, IServiceProvider services) + { + this._logger = logger; + this._services = services; + this._sources = new List(); + this._nextPoll = new(); + } + + public async Task FetchSources() + { + await using var scoped = this._services.CreateAsyncScope(); + var dbContext = scoped.ServiceProvider.GetRequiredService(); + this._sources = await dbContext.Sources.ToListAsync(); + } + + private async Task SyncSource(VersionControlSource source, ApplicationDbContext db) + { + IGitClient client = new GitBinaryClient(); + var refs = await client.GetRemoteRefs(source.UpstreamUrl); + + + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + await this.FetchSources(); + + while (!stoppingToken.IsCancellationRequested) + { + + } + } +} \ No newline at end of file -- cgit v1.3.1