Instagram: Febe legge le risposte vere (campioni dal HAR del 21/10)
Febe non estraeva nulla da Instagram per due motivi. Instagram manda i dati di storie e raccolte (GraphQL) come text/javascript, e la cattura leggeva solo le risposte dichiarate JSON: le scartava tutte. E i file di Instagram (lettori, bersagli) erano scheletri, quindi le ricette si rifiutavano di girare. Alberto ha mandato un HAR del suo browser e una guida. La guida descrive richieste costruite a mano, vietate dalle regole 2-4, e un formato che nel HAR non compare: non si usa. Dal HAR si è letta solo la forma; le risposte utili sono diventate campioni grezzi fuori dal repository, ripuliti e verificati con febe-sonda (tests/Febe.Tests/campioni/instagram). Che cosa cambia: - la cattura legge le risposte text/javascript chieste dalla pagina (mai gli script) e ogni blocco JSON incorporato nel documento della pagina, e avvisa quando un corpo atteso non arriverà; - le risposte che non parlano di contenuti (promozioni, «storia vista») si ignorano invece di valere come formato non riconosciuto; - lettori.instagram.json è confermato, con sole chiavi presenti nei campioni; identificativi delle raccolte nella forma dell'indirizzo; - bersagli.instagram.json ha le pagine viste nel traffico vero; i bersagli restano vuoti (H11): storie, raccolte, Taggati e Reel aspettano lo script tools/bersagli/raccogli-bersagli.js; - le ricette del profilo reggono dati in risposte diverse e prendono la paginazione solo dalla risposta che porta i loro post; l'elenco dei seguiti scarta i profili suggeriti; «Tu» si riconosce anche dal solo identificativo dell'account collegato; - il visualizzatore delle raccolte conta i contenuti (l'indirizzo non cambia), chiede il permesso prima di ogni contenuto e si chiude sempre; - una ricetta che la configurazione non lascia girare è «Da configurare»: non è un guasto, non si sospende, non si pianifica; le sospensioni dovute ai file vecchi si azzerano una volta al cambio dei file; - la barra laterale dice «Collegato» dal cookie di sessione; i «Post singolo» per gli indirizzi scaduti non vengono più annullati; - febe-sonda da-har; la ripulitura tiene latest_reel_media e mette un riempitivo neutro sotto le chiavi simili a segreti (gitleaks). Prove su Windows: 783 superate, 76 saltate (Chromium e Xvfb, nella CI). Nulla è stato provato contro Instagram. Dettagli e decisioni in docs/stato.md e docs/decisioni.md (righe del 25 ottobre). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b3a7c31e5a
commit
31bbbf8bb7
69 files changed
+9184
-453
No files matched your search
@@ -403,6 +403,8 @@ public static class EngineEventCodes
|
||||
public const string ManualCheck = "controlla-ora";
|
||||
public const string RecipeFailed = "ricetta-fallita";
|
||||
public const string SettingsChanged = "impostazioni-motore";
|
||||
public const string RecipeNotConfigured = "configurazione-incompleta";
|
||||
public const string CollectionConfigurationChanged = "configurazione-raccolta";
|
||||
|
||||
/// <summary>Prefix of the per-recipe lines («Appena fatto»): "ricetta." + recipe kind.</summary>
|
||||
public const string RecipePrefix = "ricetta.";
|
||||
|
||||
@@ -74,6 +74,12 @@ public enum RecipeStatus
|
||||
|
||||
/// <summary>Unexpected error; message says what happened.</summary>
|
||||
Failed,
|
||||
|
||||
/// <summary>
|
||||
/// Refused before anything was done: the target map or the reader vocabulary of the site does not have what the
|
||||
/// recipe needs yet. A state of the configuration, not a failure of the recipe: it never counts towards suspension.
|
||||
/// </summary>
|
||||
NotConfigured,
|
||||
}
|
||||
|
||||
/// <summary>Result of a recipe run, used by the scheduler to plan what comes next.</summary>
|
||||
@@ -115,6 +121,13 @@ public interface IRecipeRunner
|
||||
|
||||
/// <summary>Puts the browser on the empty rest page (end of session, pauses, night).</summary>
|
||||
Task RestAsync(CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Why <paramref name="kind"/> cannot run on the configuration of the site in use (target map, reader vocabulary),
|
||||
/// in Italian; null when it can, or when the runner cannot tell. The engine does not plan such a recipe: running it
|
||||
/// would only end in <see cref="RecipeStatus.NotConfigured"/>.
|
||||
/// </summary>
|
||||
string? NotConfiguredReason(RecipeKind kind) => null;
|
||||
}
|
||||
|
||||
/// <summary>Daily byte budget for CDN downloads (category «dati scaricati», spec §7.4).</summary>
|
||||
|
||||
@@ -259,6 +259,11 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
}
|
||||
|
||||
var kind = CheckPolicy.WantsProfileChecks(account) ? EngineTaskKind.ProfileCheck : EngineTaskKind.AccountStories;
|
||||
if (_composer.NotConfiguredReason(CheckPolicy.RecipeOf(kind)) is { } notConfigured)
|
||||
{
|
||||
return new CheckNowResult(CheckNowStatus.Refused, notConfigured + " Il controllo non parte.");
|
||||
}
|
||||
|
||||
var category = kind == EngineTaskKind.ProfileCheck ? ActionKind.ProfileOpen : ActionKind.StoryView;
|
||||
var budget = await _s.Governor.EvaluateBudgetAsync(category, accountId, ct).ConfigureAwait(false);
|
||||
if (!budget.Granted && budget.Reason != DenialReason.AccountNotContactable)
|
||||
@@ -397,6 +402,49 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
return resumed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection configuration in use: <paramref name="fingerprint"/> of the reader vocabulary and target map of the
|
||||
/// site as loaded. When it differs from the stored one — or none is stored yet, the first start that knows it —
|
||||
/// every suspension and consecutive failure of the recipes is cleared once, since they were counted against other
|
||||
/// files, with one line in the timeline when there was something to clear; then the fingerprint is stored. Called at
|
||||
/// start-up, before <see cref="StartAsync"/>. True when the configuration had changed.
|
||||
/// </summary>
|
||||
public async Task<bool> ApplyCollectionConfigurationAsync(string fingerprint, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(fingerprint);
|
||||
var settings = _s.Storage.Settings;
|
||||
if (string.Equals(await settings.GetAsync(EngineSettingKeys.CollectionConfiguration, ct).ConfigureAwait(false), fingerprint, StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
await _health.LoadAsync(ct).ConfigureAwait(false);
|
||||
var (suspended, hadFailures) = await _health.ResetAllAsync(ct).ConfigureAwait(false);
|
||||
if (suspended.Count > 0)
|
||||
{
|
||||
var names = string.Join(", ", suspended.Select(k => "«" + ItalianText.Capitalize(SessionComposer.RecipeName(k)) + "»"));
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Info,
|
||||
EngineEventCodes.CollectionConfigurationChanged,
|
||||
$"La configurazione della raccolta è cambiata: le ricette sospese ripartono ({names}).",
|
||||
ct: ct).ConfigureAwait(false);
|
||||
}
|
||||
else if (hadFailures)
|
||||
{
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Info,
|
||||
EngineEventCodes.CollectionConfigurationChanged,
|
||||
"La configurazione della raccolta è cambiata: i problemi delle ricette contati finora non valgono più.",
|
||||
ct: ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Stored last: if Febe stops in between, the next start clears again, which changes nothing.
|
||||
await settings.SetAsync(EngineSettingKeys.CollectionConfiguration, fingerprint, ct).ConfigureAwait(false);
|
||||
Wake();
|
||||
_s.Events.Publish(EngineNotificationKind.StateChanged);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Stores and applies new engine settings, then replans.</summary>
|
||||
public async Task ApplySettingsAsync(EngineSettings settings, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@@ -45,6 +45,12 @@ public static class EngineSettingKeys
|
||||
|
||||
/// <summary>Last completed Giro dei seguiti, Unix milliseconds (it read the stories bar of every followed account).</summary>
|
||||
public const string LastSweep = "motore.ultimo-giro";
|
||||
|
||||
/// <summary>
|
||||
/// Fingerprint of the collection configuration the suspensions and failure counts refer to (reader vocabulary and
|
||||
/// target map of the site, as loaded): when it changes they are cleared once.
|
||||
/// </summary>
|
||||
public const string CollectionConfiguration = "motore.configurazione-raccolta";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -28,6 +28,7 @@ public sealed record RecentAction(
|
||||
RecipeStatus.AccountUnreachable => "Non raggiungibile",
|
||||
RecipeStatus.Cancelled => "Interrotto",
|
||||
RecipeStatus.Failed => "Errore",
|
||||
RecipeStatus.NotConfigured => "Da configurare",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ namespace Febe.Core.Engine;
|
||||
|
||||
/// <summary>
|
||||
/// Consecutive failures per recipe and suspended recipes (spec §6.4: after three «formato non riconosciuto» in a row
|
||||
/// the recipe is suspended and the interface says so). Persisted in the settings table.
|
||||
/// the recipe is suspended and the interface says so). Persisted in the settings table. A refusal because the
|
||||
/// configuration of the site is incomplete (<see cref="RecipeStatus.NotConfigured"/>) is not a failure and never
|
||||
/// reaches it; a change of that configuration clears it (<see cref="ResetAllAsync"/>).
|
||||
/// </summary>
|
||||
internal sealed class RecipeHealth
|
||||
{
|
||||
@@ -110,6 +112,26 @@ internal sealed class RecipeHealth
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection configuration changed: every suspension and every consecutive failure goes, since they were
|
||||
/// counted against other files. Returns the recipes that were suspended and whether any failure was counted.
|
||||
/// </summary>
|
||||
public async Task<(IReadOnlyList<RecipeKind> Suspended, bool HadFailures)> ResetAllAsync(CancellationToken ct)
|
||||
{
|
||||
RecipeKind[] suspended;
|
||||
bool hadFailures;
|
||||
lock (_gate)
|
||||
{
|
||||
suspended = [.. _suspended.Keys.Order()];
|
||||
hadFailures = _failures.Count > 0;
|
||||
_suspended.Clear();
|
||||
_failures.Clear();
|
||||
}
|
||||
|
||||
await SaveAsync(ct).ConfigureAwait(false);
|
||||
return (suspended, hadFailures);
|
||||
}
|
||||
|
||||
private Task SaveAsync(CancellationToken ct)
|
||||
{
|
||||
string failures;
|
||||
|
||||
@@ -14,6 +14,9 @@ namespace Febe.Core.Engine;
|
||||
/// </summary>
|
||||
internal sealed class SessionComposer
|
||||
{
|
||||
/// <summary>What every line about a recipe the configuration does not let run adds (the runner's included).</summary>
|
||||
internal const string NotConfiguredTail = " Febe non la avvia finché la configurazione non è completa, e non la conta fra i problemi della ricetta.";
|
||||
|
||||
private static readonly TimeSpan DefaultWindow = TimeSpan.FromHours(16);
|
||||
|
||||
private readonly EngineServices _s;
|
||||
@@ -24,6 +27,13 @@ internal sealed class SessionComposer
|
||||
private readonly Lock _noticeGate = new();
|
||||
private readonly HashSet<(string Code, long? Account, DateOnly Day)> _notices = [];
|
||||
|
||||
// Recipes the configuration of the site does not let run. The configuration is loaded once per process, so what a
|
||||
// run learned holds until the end, and each recipe is said once (_notConfiguredSaid), not at every session.
|
||||
private readonly Lock _configurationGate = new();
|
||||
private readonly Dictionary<RecipeKind, string> _notConfigured = [];
|
||||
private readonly HashSet<RecipeKind> _notConfiguredSaid = [];
|
||||
private readonly List<string> _notConfiguredToSay = [];
|
||||
|
||||
// The interface calls SyncQueueAsync while a session may be running. A recipe's task is Running in the database
|
||||
// between its start and its bookkeeping, and then has its successor: under this gate the queue is looked at only
|
||||
// when every task is pending, in flight (_inFlight) or already replaced by its successor, never in between.
|
||||
@@ -102,6 +112,7 @@ internal sealed class SessionComposer
|
||||
|
||||
// Normally the next sweep will cover them: explicit checks only when no sweep can run, or after a long gap.
|
||||
var sweepUnavailable = _health.IsSuspended(RecipeKind.FollowingSweep)
|
||||
|| NotConfiguredReason(RecipeKind.FollowingSweep) is not null
|
||||
|| !(await _s.Governor.EvaluateBudgetAsync(ActionKind.Home, null, ct).ConfigureAwait(false)).Granted;
|
||||
var factor = sweepUnavailable ? 1 : 2;
|
||||
var uncovered = accounts.Values
|
||||
@@ -184,9 +195,9 @@ internal sealed class SessionComposer
|
||||
/// <summary>
|
||||
/// Keeps the queue in step with the accounts: a profile check and a story check (as the account wants them) for
|
||||
/// every contactable account, a look at each highlight collection on its profile, a backfill task for every account
|
||||
/// «Storico in corso», a Giro dei seguiti when someone is followed; pending planned tasks of accounts that may not be
|
||||
/// contacted are cancelled. Commands of Alberto are left alone, and so is the task of the recipe in progress: its
|
||||
/// own bookkeeping plans the next one.
|
||||
/// «Storico in corso», a Giro dei seguiti when someone is followed; pending planned tasks the account no longer wants,
|
||||
/// or of accounts that may not be contacted, are cancelled (a «Post singolo» only in the second case). Commands of
|
||||
/// Alberto are left alone, and so is the task of the recipe in progress: its own bookkeeping plans the next one.
|
||||
/// </summary>
|
||||
public async Task<Dictionary<long, Account>> SyncQueueAsync(CancellationToken ct)
|
||||
{
|
||||
@@ -212,7 +223,14 @@ internal sealed class SessionComposer
|
||||
{
|
||||
var tasks = byAccount[account.Id].Where(t => !t.IsManual).ToList();
|
||||
var wanted = WantedKinds(account);
|
||||
foreach (var task in tasks.Where(t => t.Kind != EngineTaskKind.HighlightCheck && !wanted.ContainsKey(t.Kind) && !(t.Kind == EngineTaskKind.AccountStories && t.Priority >= Options.FlaggedStoriesPriority && CheckPolicy.IsContactable(account))))
|
||||
|
||||
// Nothing is planned that the configuration of the site does not let run: it would only be refused.
|
||||
foreach (var kind in wanted.Keys.Where(k => !CanRun(CheckPolicy.RecipeOf(k))).ToList())
|
||||
{
|
||||
wanted.Remove(kind);
|
||||
}
|
||||
|
||||
foreach (var task in tasks.Where(t => !Keeps(t, account, wanted)))
|
||||
{
|
||||
await Store.Tasks.CancelAsync(task.Id, now, ct).ConfigureAwait(false);
|
||||
}
|
||||
@@ -233,12 +251,13 @@ internal sealed class SessionComposer
|
||||
}
|
||||
|
||||
var anyFollowed = accounts.Values.Any(a => a.IsFollowed && CheckPolicy.IsContactable(a));
|
||||
var sweepWanted = anyFollowed && CanRun(RecipeKind.FollowingSweep);
|
||||
var sweeps = pending.Where(t => t.Kind == EngineTaskKind.FollowingSweep && !t.IsManual).ToList();
|
||||
if (anyFollowed && sweeps.Count == 0)
|
||||
if (sweepWanted && sweeps.Count == 0)
|
||||
{
|
||||
await EnsureSweepTaskAsync(_s.Runtime.NextSessionAt ?? now, ct).ConfigureAwait(false);
|
||||
}
|
||||
else if (!anyFollowed)
|
||||
else if (!sweepWanted)
|
||||
{
|
||||
foreach (var sweep in sweeps)
|
||||
{
|
||||
@@ -246,9 +265,28 @@ internal sealed class SessionComposer
|
||||
}
|
||||
}
|
||||
|
||||
await SayNotConfiguredAsync().ConfigureAwait(false);
|
||||
return accounts;
|
||||
}
|
||||
|
||||
/// <summary>Whether <see cref="SyncQueueLockedAsync"/> leaves a pending planned task of the account where it is.</summary>
|
||||
private bool Keeps(EngineTask task, Account account, Dictionary<EngineTaskKind, DateTimeOffset?> wanted) => task.Kind switch
|
||||
{
|
||||
// One per collection: SyncHighlightsAsync.
|
||||
EngineTaskKind.HighlightCheck => true,
|
||||
|
||||
// Queued by the collection, not by the settings of the account: a series the grid did not give whole, an
|
||||
// address that expired (spec §6.5 point 5). Nothing would queue it again, so it waits while the recipe cannot
|
||||
// run, and goes only with an account that may not be contacted.
|
||||
EngineTaskKind.SinglePost => CheckPolicy.IsContactable(account),
|
||||
|
||||
// Flagged by the stories bar: kept until it runs, when it can.
|
||||
EngineTaskKind.AccountStories when task.Priority >= Options.FlaggedStoriesPriority =>
|
||||
wanted.ContainsKey(task.Kind) || (CheckPolicy.IsContactable(account) && CanRun(RecipeKind.AccountStories)),
|
||||
|
||||
_ => wanted.ContainsKey(task.Kind),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// «Raccolta in evidenza» (spec §6.3) for an account that wants «Storie in evidenza»: one task per collection the
|
||||
/// profile check found (payload: its Instagram identifier), due at once for a collection never looked at, then
|
||||
@@ -270,6 +308,11 @@ internal sealed class SessionComposer
|
||||
}
|
||||
}
|
||||
|
||||
if (collections.Count > 0 && !CanRun(RecipeKind.Highlight))
|
||||
{
|
||||
collections.Clear();
|
||||
}
|
||||
|
||||
foreach (var task in planned.Where(t => t.Payload is null || !collections.ContainsKey(t.Payload)))
|
||||
{
|
||||
await Store.Tasks.CancelAsync(task.Id, now, ct).ConfigureAwait(false);
|
||||
@@ -295,11 +338,73 @@ internal sealed class SessionComposer
|
||||
private bool InFlight(long accountId, EngineTaskKind kind, string? payload) =>
|
||||
_inFlight is { } task && task.AccountId == accountId && task.Kind == kind && (payload is null || task.Payload == payload);
|
||||
|
||||
/// <summary>The Giro dei seguiti shown in the queue at the next session.</summary>
|
||||
public Task EnsureSweepTaskAsync(DateTimeOffset dueAt, CancellationToken ct) =>
|
||||
Store.Tasks.EnqueueAsync(
|
||||
/// <summary>The Giro dei seguiti shown in the queue at the next session (when the configuration lets it run).</summary>
|
||||
public async Task EnsureSweepTaskAsync(DateTimeOffset dueAt, CancellationToken ct)
|
||||
{
|
||||
if (!CanRun(RecipeKind.FollowingSweep))
|
||||
{
|
||||
await SayNotConfiguredAsync().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await Store.Tasks.EnqueueAsync(
|
||||
new EngineTask { Kind = EngineTaskKind.FollowingSweep, DueAt = dueAt, CreatedAt = Clock.Now },
|
||||
ct);
|
||||
ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Why the configuration of the site in use (target map, reader vocabulary) does not let <paramref name="kind"/>
|
||||
/// run, as the runner says or as a run of it said; null when it can.
|
||||
/// </summary>
|
||||
internal string? NotConfiguredReason(RecipeKind kind)
|
||||
{
|
||||
lock (_configurationGate)
|
||||
{
|
||||
if (_notConfigured.TryGetValue(kind, out var known))
|
||||
{
|
||||
return known;
|
||||
}
|
||||
}
|
||||
|
||||
return _runner.NotConfiguredReason(kind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// False when the configuration does not let <paramref name="kind"/> run. The first time, its reason is kept to be
|
||||
/// said in the timeline (<see cref="SayNotConfiguredAsync"/>): once per recipe and process, not at every session.
|
||||
/// </summary>
|
||||
private bool CanRun(RecipeKind kind)
|
||||
{
|
||||
if (NotConfiguredReason(kind) is not { } reason)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lock (_configurationGate)
|
||||
{
|
||||
if (_notConfiguredSaid.Add(kind))
|
||||
{
|
||||
_notConfiguredToSay.Add(reason);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task SayNotConfiguredAsync()
|
||||
{
|
||||
string[] reasons;
|
||||
lock (_configurationGate)
|
||||
{
|
||||
reasons = [.. _notConfiguredToSay];
|
||||
_notConfiguredToSay.Clear();
|
||||
}
|
||||
|
||||
foreach (var reason in reasons)
|
||||
{
|
||||
await _s.Events.WriteAsync(EventSeverity.Warning, EngineEventCodes.RecipeNotConfigured, reason + NotConfiguredTail, ct: CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<EngineTaskKind, DateTimeOffset?> WantedKinds(Account account)
|
||||
{
|
||||
@@ -314,7 +419,7 @@ internal sealed class SessionComposer
|
||||
if (profile)
|
||||
{
|
||||
// A profile that is not followed shows its stories only on its page: one visit serves both checks.
|
||||
wanted[EngineTaskKind.ProfileCheck] = !account.IsFollowed && stories
|
||||
wanted[EngineTaskKind.ProfileCheck] = VisitServesStories(account)
|
||||
? Earliest(account.NextProfileCheckAt, account.NextStoriesCheckAt)
|
||||
: account.NextProfileCheckAt;
|
||||
}
|
||||
@@ -336,7 +441,21 @@ internal sealed class SessionComposer
|
||||
private static DateTimeOffset? Earliest(DateTimeOffset? a, DateTimeOffset? b) =>
|
||||
a is null || b is null ? null : a < b ? a : b;
|
||||
|
||||
private static bool IsStoryWork(EngineTask task, Dictionary<long, Account> accounts, DateTimeOffset now)
|
||||
/// <summary>
|
||||
/// Whether a visit of the profile also checks its stories, so that it comes at the shorter of the two intervals: a
|
||||
/// profile that is not followed, with «Storie» on, while the configuration lets «Storie di un account» run. Without
|
||||
/// it the visit is a plain profile check (story times are left as they are, for when the stories can run).
|
||||
/// </summary>
|
||||
private bool VisitServesStories(Account account) =>
|
||||
!account.IsFollowed && CheckPolicy.WantsStories(account) && CanRun(RecipeKind.AccountStories);
|
||||
|
||||
/// <summary>Interval of a visit of the profile (<see cref="CheckPolicy.VisitInterval"/> only when it serves the stories).</summary>
|
||||
private TimeSpan VisitInterval(Account account, TimeSpan window) =>
|
||||
VisitServesStories(account)
|
||||
? CheckPolicy.VisitInterval(account, window, Options.MinimumStoryChecksPerDay)
|
||||
: CheckPolicy.ProfileCheckInterval(account);
|
||||
|
||||
private bool IsStoryWork(EngineTask task, Dictionary<long, Account> accounts, DateTimeOffset now)
|
||||
{
|
||||
if (task.Kind == EngineTaskKind.AccountStories)
|
||||
{
|
||||
@@ -347,8 +466,7 @@ internal sealed class SessionComposer
|
||||
return task.Kind == EngineTaskKind.ProfileCheck
|
||||
&& task.AccountId is { } id
|
||||
&& accounts.TryGetValue(id, out var account)
|
||||
&& !account.IsFollowed
|
||||
&& CheckPolicy.WantsStories(account)
|
||||
&& VisitServesStories(account)
|
||||
&& (account.NextStoriesCheckAt is null || account.NextStoriesCheckAt <= now);
|
||||
}
|
||||
|
||||
@@ -361,7 +479,7 @@ internal sealed class SessionComposer
|
||||
{
|
||||
var interval = task.Kind == EngineTaskKind.AccountStories
|
||||
? CheckPolicy.StoryInterval(account, window, Options.MinimumStoryChecksPerDay)
|
||||
: CheckPolicy.VisitInterval(account, window, Options.MinimumStoryChecksPerDay);
|
||||
: VisitInterval(account, window);
|
||||
items.Add((task, CheckPolicy.SelectionWeight(account, now - task.DueAt, interval)));
|
||||
}
|
||||
else
|
||||
@@ -545,6 +663,15 @@ internal sealed class SessionComposer
|
||||
|
||||
var now = Clock.Now;
|
||||
var flagged = new HashSet<long>(outcome.AccountsWithStories);
|
||||
|
||||
// No check is queued that the configuration does not let run: it would only wait, and go at the next session.
|
||||
// Nothing is lost: until their stories are checked, every sweep flags these accounts again.
|
||||
if (flagged.Count > 0 && !CanRun(RecipeKind.AccountStories))
|
||||
{
|
||||
flagged.Clear();
|
||||
await SayNotConfiguredAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
foreach (var id in flagged)
|
||||
{
|
||||
if (accounts.TryGetValue(id, out var account) && CheckPolicy.IsContactable(account) && CheckPolicy.WantsStories(account))
|
||||
@@ -615,6 +742,12 @@ internal sealed class SessionComposer
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanRun(RecipeKind.Backfill))
|
||||
{
|
||||
await SayNotConfiguredAsync().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var now = Clock.Now;
|
||||
var zone = Clock.LocalZone;
|
||||
var today = LocalCalendar.Today(now, zone);
|
||||
@@ -683,6 +816,25 @@ internal sealed class SessionComposer
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!CanRun(request.Kind))
|
||||
{
|
||||
await SayNotConfiguredAsync().ConfigureAwait(false);
|
||||
if (task is { IsManual: true })
|
||||
{
|
||||
// A command of Alberto that cannot be carried out with these files: dropped, and he is told why.
|
||||
await Store.Tasks.CancelAsync(task.Id, Clock.Now, CancellationToken.None).ConfigureAwait(false);
|
||||
await _s.Events.WriteAsync(
|
||||
EventSeverity.Warning,
|
||||
EngineEventCodes.RecipeNotConfigured,
|
||||
$"La tua richiesta ({RecipeName(request.Kind)}{Of(account)}) è annullata: {NotConfiguredReason(request.Kind)}",
|
||||
account?.Id,
|
||||
state.Context.SessionId,
|
||||
CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var category = CheckPolicy.CategoryOf(request.Kind);
|
||||
if (state.Exhausted.Contains(category))
|
||||
{
|
||||
@@ -875,6 +1027,26 @@ internal sealed class SessionComposer
|
||||
$"Formato non riconosciuto durante {RecipeName(kind)}{Of(account)}: Instagram potrebbe aver cambiato le sue risposte.", now).ConfigureAwait(false);
|
||||
break;
|
||||
|
||||
case RecipeStatus.NotConfigured:
|
||||
// Not a failure: the files of the site do not let it run. Never counted towards suspension, not tried
|
||||
// again in this process (the runner has said why); a command of Alberto is dropped, planned work waits.
|
||||
lock (_configurationGate)
|
||||
{
|
||||
_notConfigured.TryAdd(kind, outcome.Message ?? $"«{ItalianText.Capitalize(RecipeName(kind))}» non può girare con la configurazione attuale.");
|
||||
_notConfiguredSaid.Add(kind);
|
||||
}
|
||||
|
||||
if (task is { IsManual: true })
|
||||
{
|
||||
writes.Add(Store.Tasks.CancelAsync(task.Id, now, ct));
|
||||
}
|
||||
else if (task is not null)
|
||||
{
|
||||
await RequeueAsync(task, "Configurazione incompleta", now).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RecipeStatus.AccountUnreachable:
|
||||
if (task is not null)
|
||||
{
|
||||
@@ -955,9 +1127,10 @@ internal sealed class SessionComposer
|
||||
{
|
||||
case RecipeKind.ProfileCheck:
|
||||
{
|
||||
// A profile not followed is visited at the earlier of its post check and its story check.
|
||||
// A profile not followed is visited at the earlier of its post check and its story check (while the
|
||||
// stories can run: otherwise only for its posts).
|
||||
var next = now + CheckPolicy.NextCheckDelay(_s.Random, CheckPolicy.ProfileCheckInterval(account));
|
||||
DateTimeOffset? storiesNext = !account.IsFollowed && CheckPolicy.WantsStories(account)
|
||||
DateTimeOffset? storiesNext = VisitServesStories(account)
|
||||
? now + CheckPolicy.NextStoryCheckDelay(_s.Random, CheckPolicy.StoryInterval(account, window, Options.MinimumStoryChecksPerDay))
|
||||
: null;
|
||||
state.LastVisitNext = storiesNext;
|
||||
@@ -1164,6 +1337,7 @@ internal sealed class SessionComposer
|
||||
RecipeStatus.UnrecognizedFormat => "Formato non riconosciuto",
|
||||
RecipeStatus.AccountUnreachable => "Non raggiungibile",
|
||||
RecipeStatus.Cancelled => "Interrotto",
|
||||
RecipeStatus.NotConfigured => "Configurazione della raccolta incompleta",
|
||||
_ => "Non riuscito",
|
||||
};
|
||||
return (title, detail);
|
||||
|
||||
Reference in new issue
Block a user