3b416c7fb2
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
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using Emby.Server.Implementations.ScheduledTasks.Tasks;
|
|
using MediaBrowser.Controller.ScheduledTasks;
|
|
using MediaBrowser.Model.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Jellyfin.Server.Implementations.Tests.ScheduledTasks;
|
|
|
|
public class ScanLeaderOptionsTests
|
|
{
|
|
/// <summary>
|
|
/// A gated key that matches no registered task silently stops gating anything, so the default
|
|
/// set is pinned to the task keys that actually exist in the build.
|
|
/// </summary>
|
|
[Fact]
|
|
public void DefaultGatedTaskKeys_Should_MatchRegisteredScheduledTasks()
|
|
{
|
|
var registeredKeys = DiscoverScheduledTaskKeys();
|
|
|
|
Assert.NotEmpty(registeredKeys);
|
|
Assert.Empty(new ScanLeaderOptions().GatedTaskKeys.Except(registeredKeys, StringComparer.Ordinal));
|
|
}
|
|
|
|
private static HashSet<string> DiscoverScheduledTaskKeys()
|
|
{
|
|
var keys = new HashSet<string>(StringComparer.Ordinal);
|
|
var assemblies = new[]
|
|
{
|
|
typeof(DeleteTranscodeFileTask).Assembly,
|
|
typeof(Jellyfin.MediaEncoding.Hls.ScheduledTasks.KeyframeExtractionScheduledTask).Assembly
|
|
};
|
|
|
|
foreach (var type in assemblies.SelectMany(a => a.GetTypes()))
|
|
{
|
|
if (type.IsAbstract || type.IsInterface || !typeof(IScheduledTask).IsAssignableFrom(type))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Task keys are constant expressions, so an uninitialised instance is enough to read
|
|
// them without standing up each task's dependency graph.
|
|
var task = (IScheduledTask)RuntimeHelpers.GetUninitializedObject(type);
|
|
keys.Add(task.Key);
|
|
}
|
|
|
|
return keys;
|
|
}
|
|
}
|