| | 1 | | using System; |
| | 2 | | using System.Threading.Tasks; |
| | 3 | | using MediaBrowser.Model.Tasks; |
| | 4 | | using Microsoft.Extensions.Logging; |
| | 5 | |
|
| | 6 | | namespace Emby.Server.Implementations.ScheduledTasks.Triggers |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Class StartupTaskTrigger. |
| | 10 | | /// </summary> |
| | 11 | | public sealed class StartupTrigger : ITaskTrigger |
| | 12 | | { |
| | 13 | | private const int DelayMs = 3000; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Initializes a new instance of the <see cref="StartupTrigger"/> class. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="taskOptions">The options of this task.</param> |
| | 19 | | public StartupTrigger(TaskOptions taskOptions) |
| | 20 | | { |
| | 21 | | TaskOptions = taskOptions; |
| 63 | 22 | | } |
| | 23 | |
|
| | 24 | | /// <inheritdoc /> |
| | 25 | | public event EventHandler<EventArgs>? Triggered; |
| | 26 | |
|
| | 27 | | /// <inheritdoc /> |
| | 28 | | public TaskOptions TaskOptions { get; } |
| | 29 | |
|
| | 30 | | /// <inheritdoc /> |
| | 31 | | public async void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup) |
| | 32 | | { |
| | 33 | | if (isApplicationStartup) |
| | 34 | | { |
| | 35 | | await Task.Delay(DelayMs).ConfigureAwait(false); |
| | 36 | |
|
| | 37 | | OnTriggered(); |
| | 38 | | } |
| | 39 | | } |
| | 40 | |
|
| | 41 | | /// <inheritdoc /> |
| | 42 | | public void Stop() |
| | 43 | | { |
| 129 | 44 | | } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Called when [triggered]. |
| | 48 | | /// </summary> |
| | 49 | | private void OnTriggered() |
| | 50 | | { |
| 60 | 51 | | Triggered?.Invoke(this, EventArgs.Empty); |
| 3 | 52 | | } |
| | 53 | | } |
| | 54 | | } |