Collegamento e motore: correzioni regole-1, regole-2, regole-6, websec-1, websec-5, websec-6, engine-1, engine-2, sched-1
Pagine aperte da Alberto non sono segnali (regole-1); cookie perso fuori sessione = disconnessione (regole-2); pagina a riposo quando Alberto lascia il browser (regole-6); la lease di «Accedi»/«Usa il browser» finisce da sola dopo 2 minuti senza vista remota né finestra (websec-1); ping con scadenza sulla vista remota (websec-5); aperture della vista remota serializzate (websec-6); orologio virtuale senza fine anticipata (engine-1); la sincronizzazione della coda non duplica il compito in corso (engine-2); raccolte in evidenza programmate (sched-1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
19 files changed
+1122
-92
No files matched your search
@@ -51,6 +51,7 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
private Task? _loop;
|
||||
private bool _initialized;
|
||||
private bool _manualWaiting;
|
||||
private int _restAfterDriving;
|
||||
private DateTimeOffset? _plannedAfterStop;
|
||||
|
||||
public EngineHost(EngineServices services, IRecipeRunner runner)
|
||||
@@ -363,11 +364,15 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
_s.Events.Publish(EngineNotificationKind.StateChanged);
|
||||
}
|
||||
|
||||
/// <summary>Alberto started or finished using the browser: when he starts, the session in progress ends at once.</summary>
|
||||
/// <summary>
|
||||
/// Alberto started or finished using the browser: when he starts, the session in progress ends at once (leaving the
|
||||
/// page to him); when he lets go, the loop puts the page back to rest.
|
||||
/// </summary>
|
||||
public void NotifyUserDrivingChanged()
|
||||
{
|
||||
if (_s.Runtime.UserIsDriving)
|
||||
{
|
||||
Volatile.Write(ref _restAfterDriving, 1);
|
||||
CancelSession();
|
||||
}
|
||||
|
||||
@@ -451,6 +456,15 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
{
|
||||
var now = _s.Clock.Now;
|
||||
var runtime = _s.Runtime;
|
||||
if (runtime.UserIsDriving)
|
||||
{
|
||||
Volatile.Write(ref _restAfterDriving, 1);
|
||||
}
|
||||
else if (Interlocked.Exchange(ref _restAfterDriving, 0) == 1)
|
||||
{
|
||||
await RestAfterDrivingAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (runtime.IsPaused)
|
||||
{
|
||||
return LongWait;
|
||||
@@ -630,6 +644,8 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
var keepPage = breaker.Status is BreakerStatus.Challenge or BreakerStatus.Disconnected || s.Runtime.UserIsDriving;
|
||||
if (!keepPage)
|
||||
{
|
||||
// This rest also serves a driving period that ended during the session.
|
||||
Interlocked.Exchange(ref _restAfterDriving, 0);
|
||||
try
|
||||
{
|
||||
await _runner.RestAsync(ct).ConfigureAwait(false);
|
||||
@@ -687,6 +703,36 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
s.Events.Publish(EngineNotificationKind.StateChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alberto let go of the browser and no session runs: the page goes back to rest (spec §6.1), so that nothing he or a
|
||||
/// cancelled session left open stays on the site — a story viewer moves on by itself to other accounts (§6.3).
|
||||
/// After a verification or a disconnection the page stays as it is until «Riprendi» (§7.6).
|
||||
/// </summary>
|
||||
private async Task RestAfterDrivingAsync(CancellationToken ct)
|
||||
{
|
||||
if (_s.Breaker.State.Status is BreakerStatus.Challenge or BreakerStatus.Disconnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _runner.RestAsync(ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException) when (ct.IsCancellationRequested)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Warning,
|
||||
EngineEventCodes.RecipeFailed,
|
||||
$"Non sono riuscito a portare il browser sulla pagina vuota ({ex.GetType().Name}).",
|
||||
ct: CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private SessionOutcome StopOutcome() =>
|
||||
_s.Breaker.State.Status == BreakerStatus.Throttled ? SessionOutcome.Throttled : SessionOutcome.Stopped;
|
||||
|
||||
|
||||
Reference in new issue
Block a user