Il motore chiude lo storico anche se la corsa finisce con un segnale
Quando il cammino dello Storico arriva in fondo, la ricetta segna lo storico come completato e lo dice al motore (BackfillFinished). Il motore però chiudeva lo storico (stato «Aggiornato» o «In pausa» e riga «Storico completato») solo se la corsa finiva «Completata»: un segnale o un'interruzione arrivati subito dopo l'ultima pagina lasciavano l'account «Storico in corso» per sempre, senza che nessuno lo riprendesse. Ora la chiusura sta in un solo punto (FinishBackfillAsync) e scatta ogni volta che il cammino è arrivato in fondo, comunque sia finita la corsa. Prova nuova per il segnale e per l'interruzione. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
edade61b72
commit
f86c794fa4
2 files changed
+93
-21
No files matched your search
@@ -771,6 +771,14 @@ internal sealed class SessionComposer
|
||||
var now = Clock.Now;
|
||||
var kind = request.Kind;
|
||||
var writes = new List<Task>();
|
||||
|
||||
// The walk reached the beginning of the profile: the history is complete however the run ended (a signal or a
|
||||
// cancellation can come right after the last page was stored, and that account would not be walked again).
|
||||
if (kind == RecipeKind.Backfill && outcome.BackfillFinished && account is not null)
|
||||
{
|
||||
await FinishBackfillAsync(account, state, now, ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
switch (outcome.Status)
|
||||
{
|
||||
case RecipeStatus.Completed:
|
||||
@@ -947,27 +955,8 @@ internal sealed class SessionComposer
|
||||
break;
|
||||
}
|
||||
|
||||
case RecipeKind.Backfill when outcome.BackfillFinished:
|
||||
{
|
||||
var fresh = await Store.Accounts.GetAsync(account.Id, ct).ConfigureAwait(false) ?? account;
|
||||
await Store.Accounts.SetBackfillAsync(account.Id, fresh.BackfillCursor, now, ct).ConfigureAwait(false);
|
||||
var newState = fresh.KeepUpdated ? AccountState.UpToDate : AccountState.Paused;
|
||||
await Store.Accounts.SetStateAsync(account.Id, newState, now, null, ct).ConfigureAwait(false);
|
||||
var total = await Store.Entries.CountDiscoveredAsync(account.Id, EntryKind.Post, DateTimeOffset.UnixEpoch, now.AddSeconds(1), ct).ConfigureAwait(false);
|
||||
var tail = fresh.KeepUpdated
|
||||
? " Da ora lo tengo aggiornato."
|
||||
: " «Tieni aggiornato» è spento: l'account resta in pausa.";
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Success,
|
||||
EngineEventCodes.BackfillCompleted,
|
||||
$"Storico di {ItalianText.Handle(account.Username)} completato: {ItalianText.Count(total, "post", "post")} in libreria.{tail}",
|
||||
account.Id,
|
||||
state.Context.SessionId,
|
||||
ct).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case RecipeKind.Backfill:
|
||||
// A history completed: FinishBackfillAsync, from ApplyOutcomeAsync.
|
||||
case RecipeKind.Backfill when !outcome.BackfillFinished:
|
||||
if (contactable)
|
||||
{
|
||||
// Behind the other accounts «Storico in corso»: they alternate.
|
||||
@@ -980,6 +969,30 @@ internal sealed class SessionComposer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The history of the account is complete: «Aggiornato» (or «In pausa» with «Tieni aggiornato» off) and the one
|
||||
/// «storico completato» line of Attività, which is also the alert (spec §13.3). The recipes write no line of their
|
||||
/// own for it.
|
||||
/// </summary>
|
||||
private async Task FinishBackfillAsync(Account account, SessionState state, DateTimeOffset now, CancellationToken ct)
|
||||
{
|
||||
var fresh = await Store.Accounts.GetAsync(account.Id, ct).ConfigureAwait(false) ?? account;
|
||||
await Store.Accounts.SetBackfillAsync(account.Id, fresh.BackfillCursor, now, ct).ConfigureAwait(false);
|
||||
var newState = fresh.KeepUpdated ? AccountState.UpToDate : AccountState.Paused;
|
||||
await Store.Accounts.SetStateAsync(account.Id, newState, now, null, ct).ConfigureAwait(false);
|
||||
var total = await Store.Entries.CountDiscoveredAsync(account.Id, EntryKind.Post, DateTimeOffset.UnixEpoch, now.AddSeconds(1), ct).ConfigureAwait(false);
|
||||
var tail = fresh.KeepUpdated
|
||||
? " Da ora lo tengo aggiornato."
|
||||
: " «Tieni aggiornato» è spento: l'account resta in pausa.";
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Success,
|
||||
EngineEventCodes.BackfillCompleted,
|
||||
$"Storico di {ItalianText.Handle(account.Username)} completato: {ItalianText.Count(total, "post", "post")} in libreria.{tail}",
|
||||
account.Id,
|
||||
state.Context.SessionId,
|
||||
ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task PauseAfterSingleDownloadAsync(Account account, DateTimeOffset now, SessionState state, CancellationToken ct)
|
||||
{
|
||||
await Store.Accounts.SetStateAsync(account.Id, AccountState.Paused, now, null, ct).ConfigureAwait(false);
|
||||
|
||||
Reference in new issue
Block a user