aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Tasks/ITaskManager.cs
blob: 6066bbde49e09ca4e0d786a741b625557f18f111 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Jellyfin.Data.Events;

namespace MediaBrowser.Model.Tasks
{
    /// <summary>
    /// Interface for the TaskManager class.
    /// </summary>
    public interface ITaskManager : IDisposable
    {
        /// <summary>
        /// Event handler for task execution.
        /// </summary>
        event EventHandler<GenericEventArgs<IScheduledTaskWorker>>? TaskExecuting;

        /// <summary>
        /// Event handler for task completion.
        /// </summary>
        event EventHandler<TaskCompletionEventArgs>? TaskCompleted;

        /// <summary>
        /// Gets the list of Scheduled Tasks.
        /// </summary>
        /// <value>The scheduled tasks.</value>
        IReadOnlyList<IScheduledTaskWorker> ScheduledTasks { get; }

        /// <summary>
        /// Cancels if running and queue.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        /// <param name="options">Task options.</param>
        void CancelIfRunningAndQueue<T>(TaskOptions options)
            where T : IScheduledTask;

        /// <summary>
        /// Cancels if running and queue.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        void CancelIfRunningAndQueue<T>()
            where T : IScheduledTask;

        /// <summary>
        /// Cancels if running.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        void CancelIfRunning<T>()
            where T : IScheduledTask;

        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        /// <param name="options">Task options.</param>
        void QueueScheduledTask<T>(TaskOptions options)
            where T : IScheduledTask;

        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        void QueueScheduledTask<T>()
            where T : IScheduledTask;

        /// <summary>
        /// Queues the scheduled task if it is not already running.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        void QueueIfNotRunning<T>()
            where T : IScheduledTask;

        /// <summary>
        /// Queues the scheduled task.
        /// </summary>
        /// <param name="task">The <see cref="IScheduledTask" /> to queue.</param>
        /// <param name="options">The <see cref="TaskOptions" /> to use.</param>
        void QueueScheduledTask(IScheduledTask task, TaskOptions options);

        /// <summary>
        /// Adds the tasks.
        /// </summary>
        /// <param name="tasks">The tasks.</param>
        void AddTasks(IEnumerable<IScheduledTask> tasks);

        /// <summary>
        /// Adds the tasks.
        /// </summary>
        /// <param name="task">The tasks.</param>
        void Cancel(IScheduledTaskWorker task);

        /// <summary>
        /// Executes the tasks.
        /// </summary>
        /// <param name="task">The tasks.</param>
        /// <param name="options">The options.</param>
        /// <returns>The executed tasks.</returns>
        Task Execute(IScheduledTaskWorker task, TaskOptions options);

        /// <summary>
        /// Executes the tasks.
        /// </summary>
        /// <typeparam name="T">An implementation of <see cref="IScheduledTask" />.</typeparam>
        void Execute<T>()
            where T : IScheduledTask;
    }
}