Repository navigation
Expand file tree
/
Copy pathPrecacheTask.cs
More file actions
49 lines (39 loc) · 1.47 KB
/
Copy pathPrecacheTask.cs
File metadata and controls
49 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using MediaBrowser.Model.Tasks;
namespace JellyPrecache;
// Fills Jellyfin's resize cache with every configured width and format of every enabled image type.
public class PrecacheTask : IScheduledTask
{
public const string TaskKey = "JellyPrecachePregenerate";
private readonly ImageGenerator _generator;
private readonly StatusStore _status;
public PrecacheTask(ImageGenerator generator, StatusStore status)
{
_generator = generator;
_status = status;
}
public string Name => "Pre-generate image sizes";
public string Key => TaskKey;
public string Description => "Resizes library images to the widths configured in JellyPrecache, so browsing never reads originals.";
public string Category => "JellyPrecache";
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfoType.DailyTrigger,
TimeOfDayTicks = TimeSpan.FromHours(4).Ticks
};
}
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
await _generator.TaskLock.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var run = await _generator.GenerateAll(progress, cancellationToken).ConfigureAwait(false);
_status.Record(TaskKey, run.Elapsed, run.Summary(), run);
}
finally
{
_generator.TaskLock.Release();
}
}
}