Files
unkin-agent 3b416c7fb2 feat: gate periodic library tasks behind a scan-leader lease
Timer-driven library tasks fire on every replica, so a library refresh or a
database optimise runs once per pod against the same shared library.

- add IScanLeaderLease with a Redis TTL implementation and a no-op default
- skip timer-driven runs of the gated tasks on instances without the lease
- treat an unreachable Redis as holding the lease so tasks never stop running
- leave manual and API-triggered runs ungated
2026-09-11 23:56:51 +10:00

22 lines
785 B
C#

using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.ScheduledTasks;
/// <summary>
/// Provides a distributed leader lease that gates periodic, library-mutating scheduled tasks
/// to a single instance across a multi-pod deployment.
/// </summary>
public interface IScanLeaderLease
{
/// <summary>
/// Attempts to acquire the scan-leader lease, or renews it when this instance already holds it.
/// </summary>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>
/// <c>true</c> if this instance holds the leader lease and gated periodic tasks may run here;
/// otherwise <c>false</c>.
/// </returns>
Task<bool> TryAcquireOrRenewAsync(CancellationToken cancellationToken = default);
}