Commit Graph

68 Commits

Author SHA1 Message Date
unkinben 0008bde28e Gate periodic library-mutating tasks behind a scan-leader lease
ABI Compatibility / ABI - HEAD (pull_request) Has been cancelled
ABI Compatibility / ABI - BASE (pull_request) Has been cancelled
OpenAPI / OpenAPI - HEAD (pull_request) Has been cancelled
OpenAPI / OpenAPI - BASE (pull_request) Has been cancelled
Tests / run-phase5-tests (pull_request) Has been cancelled
Tests / run-tests (pull_request) Has been cancelled
Project Automation / Project board (pull_request) Has been cancelled
Merge Conflict Labeler / Labeling (pull_request) Has been cancelled
ABI Compatibility / ABI - Difference (pull_request) Has been cancelled
OpenAPI / OpenAPI - Difference (pull_request) Has been cancelled
OpenAPI / OpenAPI - Publish Unstable Spec (pull_request) Has been cancelled
OpenAPI / OpenAPI - Publish Stable Spec (pull_request) Has been cancelled
In a multi-pod deployment every pod runs the scheduled-task timers, so
periodic library-mutating tasks (library refresh, people/chapter refresh,
audio normalization, media-segment and keyframe extraction, collection and
user-data cleanup, database optimization) fire concurrently against the shared
database and library, duplicating work and racing each other.

Add an IScanLeaderLease abstraction that elects a single scan leader via a
Redis TTL lease keyed on the pod identity, mirroring the existing transcode
lease machinery. RedisScanLeaderLease acquires or renews the lease with an
atomic Lua script and fails safe by treating the pod as leader whenever Redis
is unreachable, so scans never stall. NullScanLeaderLease preserves the
single-instance behavior when election is disabled or no Redis connection is
configured.

Gate only the timer-driven path in ScheduledTaskWorker: when election is
enabled and a task key is in the gated set, a non-leader re-arms its trigger
and skips enqueueing. Manual and API-triggered runs bypass this path and still
run on any pod. Wiring is additive and the new worker constructor parameters
are optional, so existing behavior is unchanged when election is off.

Signed-off-by: Ben Vincent <ben@unkin.net>
2026-08-10 23:51:18 +10:00
Shadowghost 5c9f70c375 Cleanup Tasks and Validators 2025-04-30 09:29:13 +02:00
Josh Soref 044cf9fb85 chore: fix spelling
* a
* acceleration
* addition
* altogether
* api clients
* artist
* associated
* bandwidth
* cannot
* capabilities
* case-insensitive
* case-sensitive
* configuration
* delimiter
* dependent
* diacritics
* directors
* enable
* explicitly
* filters
* finish
* have
* hierarchy
* implicit
* include
* information
* into
* its
* keepalive
* localization
* macos
* manual
* matching
* metadata
* nonexistent
* options
* overridden
* parsed
* parser
* playback
* preferring
* processes
* processing
* provider
* ratings
* retrieval
* running
* segments
* separate
* should
* station
* subdirectories
* superseded
* supported
* system
* than
* the
* throws
* transpose
* valid
* was

link: forum or chat rooms

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2025-01-25 20:05:15 -05:00
Daniyar Alpyspayev 2614fecf8d move to new System.Threading.Lock type for better performance 2024-12-12 18:10:06 +05:00
Ethan Pippin 06923cbf2b Implement TaskTriggerInfoType enum (#12783) 2024-12-01 17:08:37 -07:00
Shadowghost 08ed0a9a5d Cleanup tasks 2024-09-04 17:38:10 +02:00
Bond-009 3feb3f81bf More efficient array creation (#11468) 2024-04-30 13:32:59 -06:00
Patrick Barron 8698b90594 Remove SimpleProgress 2024-02-06 09:50:46 -05:00
Bond_009 d280dc6554 Reduce log spam
Fixes #7801
2023-03-01 16:43:55 +01:00
Bond_009 52194f56b5 Replace != null with is not null 2022-12-05 15:01:13 +01:00
Bond_009 c7d50d640e Replace == null with is null 2022-12-05 15:00:20 +01:00
Bond_009 a9a5fcde81 Use ArgumentNullException.ThrowIfNull helper method
Did a simple search/replace on the whole repo (except the RSSDP project)
This reduces LOC and should improve performance (methods containing a throw statement don't get inlined)

```
if \((\w+) == null\)
\s+\{
\s+throw new ArgumentNullException\((.*)\);
\s+\}
```

```
ArgumentNullException.ThrowIfNull($1);
```
2022-10-06 20:21:23 +02:00
Bond_009 5732e6188c Fix some warnings 2022-02-15 18:59:46 +01:00
Bond_009 ea8f40e84a More cleanup 2021-12-27 14:20:05 +00:00
Bond_009 1d19a5be61 Fix some warnings
down to 580
2021-11-09 22:29:33 +01:00
Patrick Barron 4ba9b6c305 Fix warnings in ScheduledTasks 2021-10-02 12:53:51 -04:00
Cody Robibero cba07b1ca6 Remove more and more warnings 2021-08-28 16:32:50 -06:00
Bond_009 6f8ccab788 Move non-jellyfin extensions to separate project 2021-06-19 18:04:46 +02:00
Bond_009 0bc0601442 Fix some warnings 2021-05-28 14:33:54 +02:00
Bond_009 7e8428e588 Enable nullable reference types for Emby.Server.Implementations 2021-05-20 22:48:53 +02:00
BaronGreenback 2e98de9062 Code Clean up: Convert to null-coalescing operator ?? (#5845)
Co-authored-by: Cody Robibero <cody@robibe.ro>
Co-authored-by: Patrick Barron <18354464+barronpm@users.noreply.github.com>
2021-05-05 13:51:14 +02:00
BaronGreenback f2c10471bf Code Clean up: Use Pattern Matching (#5838)
Co-authored-by: Cody Robibero <cody@robibe.ro>
Co-authored-by: Patrick Barron <18354464+barronpm@users.noreply.github.com>
2021-05-05 13:37:36 +02:00
BaronGreenback bc1cc2d04a Remove unused using directives 2021-04-17 11:37:55 +01:00
cvium 42bcf171d9 Use sync Serialize when writing scheduled tasks to disk 2021-04-10 23:54:35 +02:00
Bond_009 a8ed753f6c FxCop -> Net Analyzers (part 2) 2021-03-13 22:33:28 +01:00
dkanada 54a3ab15a3 Merge pull request #5005 from jellyfin/bytes
JsonSerializer deserialize from bytes where possible
2021-02-05 11:47:06 +09:00
Bond_009 1752423e52 Open FileStream with FileMode.Create instead of FileMode.OpenOrCreate
> The OpenWrite method opens a file if one already exists for the file path,
    or creates a new file if one does not exist. For an existing file,
    it does not append the new text to the existing text. Instead,
    it overwrites the existing characters with the new characters.
    If you overwrite a longer string
    (such as "This is a test of the OpenWrite method") with a shorter string
    (such as "Second run"), the file will contain a mix of the strings
    ("Second runtest of the OpenWrite method").

Ref: https://docs.microsoft.com/en-us/dotnet/api/system.io.file.openwrite?view=net-5.0#remarks
2021-01-12 15:51:32 +01:00
Bond_009 1ea2b200c0 JsonSerializer deserialize from bytes where possible
This is faster and uses way less memory
```
BenchmarkDotNet=v0.12.1, OS=fedora 32
Intel Core i7-6700HQ CPU 2.60GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.100
  [Host]     : .NET Core 5.0.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT
  DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT

| Method |     Mean |   Error |  StdDev |   Gen 0 | Gen 1 | Gen 2 | Allocated |
|------- |---------:|--------:|--------:|--------:|------:|------:|----------:|
|  Bytes | 158.4 us | 2.56 us | 2.14 us | 16.8457 |     - |     - |  52.08 KB |
| String | 172.8 us | 0.78 us | 0.70 us | 41.5039 |     - |     - | 127.82 KB |
| Custom | 155.5 us | 2.95 us | 2.76 us | 10.0098 |     - |     - |  31.27 KB |
```
2021-01-12 15:28:02 +01:00
David 3dec1fd6b2 Use UTF8 encoding and async correctly 2020-12-29 00:35:59 +01:00
David 21fd124bca Code revie 2020-12-27 11:15:46 +01:00
David 043d045448 Put json serializer options in private field 2020-12-24 11:22:34 +01:00
David e835dfb27d Use sync string instead of file 2020-12-24 10:31:51 +01:00
David 2a574914ea Use streams instead of strings 2020-12-23 19:24:58 +01:00
David f38970cbd3 Remove xml docs 2020-12-23 15:03:14 +01:00
David 196388d607 Remove custom Json serializer from Emby.Server.Implementations 2020-12-23 13:14:40 +01:00
Bond_009 d4e568c8bf Replace Task.WaitAll with Task.Wait 2020-11-14 20:30:08 +01:00
Bond_009 49569ca0a0 Use nameof where possible 2020-10-17 16:19:57 +02:00
Patrick Barron 9fa4fff15d Merge branch 'master' into event-rewrite-1
# Conflicts:
#	Emby.Dlna/Emby.Dlna.csproj
#	Emby.Dlna/Eventing/DlnaEventManager.cs
#	Emby.Dlna/Service/BaseService.cs
#	Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
#	MediaBrowser.Controller/Subtitles/SubtitleDownloadEventArgs.cs
2020-08-24 20:04:13 -04:00
Bond_009 ab2147751f Make MediaBrowser.MediaEncoding warnings free 2020-08-20 12:16:24 +02:00
Patrick Barron ca1f15af19 Move GenericEventArgs to Jellyfin.Data.Events 2020-08-13 20:52:55 -04:00
Bond-009 9af6eda0b4 Merge pull request #3343 from telans/comment-stops
Add full stop at end of comments (SA1629)
2020-06-16 11:54:58 +02:00
telans 247f9c61e6 fix SA1513/SA1516 2020-06-16 16:11:30 +12:00
telans 9018f8d8be Add full stop at end of comments (SA1629) 2020-06-16 10:37:52 +12:00
Vasily 40502a33e0 Merge pull request #3203 from Bond-009/warn18
Enable TreatWarningsAsErrors for Jellyfin.Server.Implementations in Release mode
2020-06-03 12:27:59 +03:00
Bond_009 4748105dce Enable TreatWarningsAsErrors for Jellyfin.Server.Implementations in Release mode 2020-05-29 11:28:19 +02:00
Bond_009 30ce346f34 Enable nullabe reference types for MediaBrowser.Model 2020-04-05 18:10:56 +02:00
Bond-009 b477b3874e Fix some warnings 2019-11-22 16:15:31 +01:00
Bond-009 6032f31aa6 Use CultureInvariant string conversion for Guids 2019-08-09 23:17:54 +02:00
Bond-009 d0f2b3a747 Merge branch 'master' into startuptasks 2019-01-30 16:55:07 +01:00
Erwin de Haan d7c6d16250 Unwrapped CreateDirectory and DeleteDirectory 2019-01-28 22:09:56 +01:00