Publish the image on version tags and test what is delivered
A v* tag now builds, tries and publishes the image: the version must be the one of Directory.Build.props, latest only moves forward and the registry token is in one step, given to docker on its input. The same script works by hand. The image says its version and commit, and its health check also covers the engine loop and the live prices. The Unraid template is final: a test compares it with appendix E and with the variables the loader really reads, and another reads the workflow. refs #70 refs #71 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d92a39fef
commit
3cd214ae78
16 files changed
+859
-27
No files matched your search
@@ -39,7 +39,7 @@ internal static partial class Endpoints
|
||||
Forms.Map(app);
|
||||
}
|
||||
|
||||
// Healthy only when the database answers and the scheduler loop is alive (SPEC 15.2); the body says why not.
|
||||
// Healthy only when the database answers, the loops turn and the prices arrive (SPEC 15.2); the body says why not.
|
||||
private static async Task<IResult> HealthAsync(AnubisHost host, CancellationToken cancellationToken)
|
||||
{
|
||||
var status = host.Status;
|
||||
@@ -62,6 +62,11 @@ internal static partial class Endpoints
|
||||
|
||||
checks["scheduler"] = host.SchedulerRunning ? "ok" : "fermo";
|
||||
healthy &= host.SchedulerRunning;
|
||||
var (loop, loopOk) = HealthRules.Loop(host.Clock.UtcNow, services.Trading is { IsStarted: true }, services.Trading?.LastTurnAt);
|
||||
var (feed, feedOk) = HealthRules.Feed(host.Clock.UtcNow, services.MarketData?.LiveFeed.Since, services.MarketData?.LiveFeed.LastDataAt);
|
||||
checks["motore"] = loop;
|
||||
checks["dati"] = feed;
|
||||
healthy &= loopOk && feedOk;
|
||||
}
|
||||
|
||||
var body = new HealthResponse(healthy ? "ok" : "unavailable", AnubisInfo.Name, AnubisInfo.Version, status.Mode.ToString(), checks);
|
||||
@@ -500,3 +505,29 @@ internal static partial class Endpoints
|
||||
given is not null && expected is not null &&
|
||||
CryptographicOperations.FixedTimeEquals(SHA256.HashData(Encoding.UTF8.GetBytes(given)), SHA256.HashData(Encoding.UTF8.GetBytes(expected)));
|
||||
}
|
||||
|
||||
/// <summary>What the health check of the container says about the engine's loop and the live prices (SPEC 15.2).</summary>
|
||||
internal static class HealthRules
|
||||
{
|
||||
/// <summary>The same silence after which the guard steps in (SPEC 9.3).</summary>
|
||||
public static readonly TimeSpan LoopLimit = TimeSpan.FromMinutes(2);
|
||||
|
||||
/// <summary>Longer than the silence that blocks new entries (SPEC 6.5): a line that drops for a moment is not an ill container.</summary>
|
||||
public static readonly TimeSpan FeedLimit = TimeSpan.FromMinutes(5);
|
||||
|
||||
public static (string Text, bool Ok) Loop(DateTimeOffset now, bool started, DateTimeOffset? lastTurn) => (started, lastTurn) switch
|
||||
{
|
||||
(false, _) => ("non avviato", true),
|
||||
(_, null) => ("in avvio", true),
|
||||
(_, { } at) when now - at > LoopLimit => ("fermo", false),
|
||||
_ => ("ok", true),
|
||||
};
|
||||
|
||||
public static (string Text, bool Ok) Feed(DateTimeOffset now, DateTimeOffset? since, DateTimeOffset? lastData) => (since, lastData) switch
|
||||
{
|
||||
(null, _) => ("in attesa", true),
|
||||
({ } from, null) when now - from <= FeedLimit => ("in attesa", true),
|
||||
(_, { } at) when now - at <= FeedLimit => ("ok", true),
|
||||
_ => ("fermi", false),
|
||||
};
|
||||
}
|
||||
@@ -147,9 +147,18 @@ internal sealed record SystemView(
|
||||
? new SystemPart("Prezzi di mercato", "aggiornati " + Ago(now - at), now - at > TimeSpan.FromMinutes(5) ? PartState.Warn : PartState.Ok)
|
||||
: new SystemPart("Prezzi di mercato", "in attesa dei primi prezzi", PartState.Off));
|
||||
|
||||
// News arrive with phase 7 (SPEC 10).
|
||||
parts.Add(new SystemPart("Lettura delle notizie", "non ancora attiva", PartState.Off));
|
||||
tiles.Add(new SystemPart("Notizie", "non ancora attive", PartState.Off));
|
||||
// The news sources read every two minutes (SPEC 4.4): the ones the user left on, and when one last answered.
|
||||
var read = market is null || market.Offline ? [] : (await market.News.Store.ListSourcesAsync(cancellationToken).ConfigureAwait(false)).Where(s => s.Enabled).ToList();
|
||||
var heard = read.Max(s => s.LastOkAt);
|
||||
var (newsText, newsState) = (read.Count, heard) switch
|
||||
{
|
||||
(0, _) => ("spenta", PartState.Off),
|
||||
(_, null) => ("in attesa della prima lettura", PartState.Off),
|
||||
(_, { } last) when now - last > TimeSpan.FromMinutes(30) => ("le fonti non rispondono, ultima lettura " + When(last, now, zone) + ": riprovo da solo", PartState.Warn),
|
||||
(_, { } last) => ($"{read.Count} fonti, ultima lettura {When(last, now, zone)}", PartState.Ok),
|
||||
};
|
||||
parts.Add(new SystemPart("Lettura delle notizie", newsText, newsState));
|
||||
tiles.Add(new SystemPart("Notizie", heard is { } h ? "lette " + When(h, now, zone) : newsText, newsState));
|
||||
|
||||
// The database: engine, size, last backup.
|
||||
var engine = services.Db.Engine == DbEngine.Postgres ? "PostgreSQL" : "SQLite";
|
||||
|
||||
@@ -75,6 +75,12 @@ public sealed partial class MarketCollector
|
||||
/// <summary>True while the live feed is connected.</summary>
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
/// <summary>When the last datum arrived from the live feed, by this computer's clock; null before the first.</summary>
|
||||
public DateTimeOffset? LastDataAt { get; private set; }
|
||||
|
||||
/// <summary>When the live feed was started, by this computer's clock; null before that.</summary>
|
||||
public DateTimeOffset? LiveSince { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the daily bars after the last one stored (from <paramref name="from"/> the first time) up to yesterday.
|
||||
/// <paramref name="prefetched"/>, when given, are bars already downloaded for many symbols at once: only the second
|
||||
@@ -195,6 +201,7 @@ public sealed partial class MarketCollector
|
||||
foreach (var instrument in instruments)
|
||||
{
|
||||
_freshness.Follow(instrument.Id, instrument.Symbol);
|
||||
LiveSince ??= _clock.UtcNow;
|
||||
}
|
||||
|
||||
var recent = new Dictionary<Guid, List<Bar>>();
|
||||
@@ -248,10 +255,12 @@ public sealed partial class MarketCollector
|
||||
}
|
||||
|
||||
_freshness.Touch(instrument.Id, closed.Bar.OpensAt.AddMinutes(1));
|
||||
LastDataAt = _clock.UtcNow;
|
||||
}
|
||||
else if (item is not BarEvent)
|
||||
{
|
||||
_freshness.Touch(instrument.Id, item.At);
|
||||
LastDataAt = _clock.UtcNow;
|
||||
}
|
||||
|
||||
_bus.Publish(item);
|
||||
|
||||
@@ -113,6 +113,9 @@ public sealed partial class MarketDataService : IDisposable
|
||||
/// <summary>True while the live crypto feed is connected.</summary>
|
||||
public bool LiveConnected => _okxCollector.Connected;
|
||||
|
||||
/// <summary>When the live crypto feed was started and when its last datum arrived: a feed open and silent is not healthy (trap 10).</summary>
|
||||
public (DateTimeOffset? Since, DateTimeOffset? LastDataAt) LiveFeed => (_okxCollector.LiveSince, _okxCollector.LastDataAt);
|
||||
|
||||
/// <summary>When the background worker last finished a round, for the interface.</summary>
|
||||
public DateTimeOffset? LastHistoryRun { get; private set; }
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ public static class DockerPlatform
|
||||
var port = ParsePort(Get("PORT"), 8787, "PORT", problems);
|
||||
var puid = ParseInt(Get("PUID"), 99, "PUID", problems);
|
||||
var pgid = ParseInt(Get("PGID"), 100, "PGID", problems);
|
||||
if (puid == 0)
|
||||
{
|
||||
problems.Add(new("PUID", "Anubis non gira come amministratore del sistema.", "Usa un utente normale (99 su Unraid) e riavvia."));
|
||||
}
|
||||
|
||||
var keys = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var name in OptionalKeys.SelectMany(k => new[] { k, k + "_DEMO" }))
|
||||
|
||||
@@ -688,6 +688,9 @@ public sealed partial class TradingService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>When the working loop last finished a turn, for the health check; null before the first.</summary>
|
||||
public DateTimeOffset? LastTurnAt { get; private set; }
|
||||
|
||||
/// <summary>The working loop: quotes from the stream, order updates from the brokers, a turn of every account every few seconds.</summary>
|
||||
public async Task RunAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -703,6 +706,7 @@ public sealed partial class TradingService : IDisposable
|
||||
}
|
||||
|
||||
await TickAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
LastTurnAt = _clock.UtcNow;
|
||||
BeatIfAlive();
|
||||
if (GuardFiles is not null && _clock.UtcNow - _guardStateAt >= GuardStateEvery)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user