House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -11,13 +11,11 @@ using System.Globalization;
|
||||
|
||||
namespace PrivaPub.Infrastructure.Statistics
|
||||
{
|
||||
public class RollupJob : IJobHandler
|
||||
public class RollupJob(
|
||||
IJobQueue queue) : IJobHandler
|
||||
{
|
||||
public static readonly TimeSpan After = TimeSpan.FromMinutes(30);
|
||||
|
||||
readonly IJobQueue _queue;
|
||||
|
||||
public RollupJob(IJobQueue queue) => _queue = queue;
|
||||
|
||||
public JobKind Kind => JobKind.RollupDay;
|
||||
public int Concurrency => 1;
|
||||
@@ -47,7 +45,7 @@ namespace PrivaPub.Infrastructure.Statistics
|
||||
await DB.Default.DeleteAsync<InteractionSalt>(s => s.Day == day);
|
||||
var next = end;
|
||||
if (next < DateTime.UtcNow.Date.AddDays(1))
|
||||
await _queue.EnqueueMany(new[] { For(next) }, token);
|
||||
await queue.EnqueueMany(new[] { For(next) }, token);
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
|
||||
@@ -95,21 +93,14 @@ namespace PrivaPub.Infrastructure.Statistics
|
||||
}
|
||||
}
|
||||
|
||||
public class StatisticsSchedule : BackgroundService
|
||||
public class StatisticsSchedule(
|
||||
IJobQueue queue,
|
||||
ILogger<StatisticsSchedule> logger,
|
||||
IOptionsMonitor<StatisticsOptions> options = default) : BackgroundService
|
||||
{
|
||||
static readonly TimeSpan Interval = TimeSpan.FromHours(1);
|
||||
const int CatchUpDays = 7;
|
||||
|
||||
readonly IJobQueue _queue;
|
||||
readonly ILogger<StatisticsSchedule> _logger;
|
||||
readonly IOptionsMonitor<StatisticsOptions> _options;
|
||||
|
||||
public StatisticsSchedule(IJobQueue queue, ILogger<StatisticsSchedule> logger, IOptionsMonitor<StatisticsOptions> options = default)
|
||||
{
|
||||
_queue = queue;
|
||||
_logger = logger;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
@@ -121,7 +112,7 @@ namespace PrivaPub.Infrastructure.Statistics
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
_logger.LogWarning(ex, "Statistics rollups could not be planned");
|
||||
logger.LogWarning(ex, "Statistics rollups could not be planned");
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -146,12 +137,12 @@ namespace PrivaPub.Infrastructure.Statistics
|
||||
if (!rolled && await DB.Default.Find<InteractionEvent>().Match(e => e.At >= day && e.At < end).ExecuteAnyAsync(token))
|
||||
jobs.Add(RollupJob.For(day));
|
||||
}
|
||||
if (_options?.CurrentValue.Crawler.Enabled == true)
|
||||
if (options?.CurrentValue.Crawler.Enabled == true)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
jobs.Add(Federation.Crawler.CrawlPlanner.For(new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0, DateTimeKind.Utc)));
|
||||
}
|
||||
await _queue.EnqueueMany(jobs, token);
|
||||
await queue.EnqueueMany(jobs, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user