diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-09-03 23:06:05 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-09-03 23:06:05 +1000 |
| commit | 7c33b3f334cf91918add7af08866f2ea37ed9c3f (patch) | |
| tree | 8095a2d65e87a808fac62b47e315a4875cc86b73 /src/marlin.web/Services | |
chore: initial commit
Diffstat (limited to 'src/marlin.web/Services')
| -rw-r--r-- | src/marlin.web/Services/DatabaseUpgrader.cs | 45 | ||||
| -rw-r--r-- | src/marlin.web/Services/JobService.cs | 6 | ||||
| -rw-r--r-- | src/marlin.web/Services/VersionControlSyncService.cs | 50 |
3 files changed, 101 insertions, 0 deletions
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<DatabaseUpgrader> _logger; + private readonly IServiceProvider _serviceProvider; + + public DatabaseUpgrader(ILogger<DatabaseUpgrader> 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<ApplicationDbContext>(); + + 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<VersionControlSyncService> _logger; + private readonly IServiceProvider _services; + + private ICollection<VersionControlSource> _sources; + private Dictionary<Guid, DateTime> _nextPoll; + + public VersionControlSyncService(ILogger<VersionControlSyncService> logger, IServiceProvider services) + { + this._logger = logger; + this._services = services; + this._sources = new List<VersionControlSource>(); + this._nextPoll = new(); + } + + public async Task FetchSources() + { + await using var scoped = this._services.CreateAsyncScope(); + var dbContext = scoped.ServiceProvider.GetRequiredService<ApplicationDbContext>(); + 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 |
