diff --git a/Kyoo.Common/Controllers/ITaskManager.cs b/Kyoo.Common/Controllers/ITaskManager.cs index 88e796fb..5c926eeb 100644 --- a/Kyoo.Common/Controllers/ITaskManager.cs +++ b/Kyoo.Common/Controllers/ITaskManager.cs @@ -1,9 +1,13 @@ +using System.Collections.Generic; +using Kyoo.Models; + namespace Kyoo.Controllers { public interface ITaskManager { bool StartTask(string taskSlug, string arguments = null); - + ITask GetRunningTask(); void ReloadTask(); + IEnumerable GetAllTasks(); } } \ No newline at end of file diff --git a/Kyoo.Common/Models/Task.cs b/Kyoo.Common/Models/Task.cs index 998ce4e6..f00b24c2 100644 --- a/Kyoo.Common/Models/Task.cs +++ b/Kyoo.Common/Models/Task.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -13,5 +14,7 @@ namespace Kyoo.Models public bool RunOnStartup { get; } public int Priority { get; } public Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string arguments = null); + public IEnumerable GetPossibleParameters(); + public int? Progress(); } } \ No newline at end of file diff --git a/Kyoo/Controllers/TaskManager.cs b/Kyoo/Controllers/TaskManager.cs index ce8ad216..d63dfb0a 100644 --- a/Kyoo/Controllers/TaskManager.cs +++ b/Kyoo/Controllers/TaskManager.cs @@ -16,6 +16,7 @@ namespace Kyoo.Controllers private List _tasks = new List(); private CancellationTokenSource _taskToken = new CancellationTokenSource(); + private ITask _runningTask; private Queue<(ITask, string)> _queuedTasks = new Queue<(ITask, string)>(); public TaskManager(IServiceProvider serviceProvider, IPluginManager pluginManager) @@ -31,10 +32,14 @@ namespace Kyoo.Controllers if (_queuedTasks.Any()) { (ITask task, string arguments) = _queuedTasks.Dequeue(); + _runningTask = task; await task.Run(_serviceProvider, _taskToken.Token, arguments); } else - await Task.Delay(1000, cancellationToken); + { + + await Task.Delay(1000_000, cancellationToken); + } } } @@ -60,6 +65,11 @@ namespace Kyoo.Controllers _queuedTasks.Enqueue((task, arguments)); return true; } + + public ITask GetRunningTask() + { + return _runningTask; + } public void ReloadTask() { @@ -70,5 +80,10 @@ namespace Kyoo.Controllers foreach (IPlugin plugin in _pluginManager.GetAllPlugins()) _tasks.AddRange(plugin.Tasks); } + + public IEnumerable GetAllTasks() + { + return _tasks; + } } } \ No newline at end of file diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index e65fb15a..77cfe2a7 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -26,6 +26,16 @@ namespace Kyoo.Controllers private ITranscoder _transcoder; private IConfiguration _config; + public IEnumerable GetPossibleParameters() + { + return _libraryManager.GetLibraries().Select(x => x.Slug); + } + + public int? Progress() + { + // TODO implement this later. + return null; + } public async Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string argument = null) { diff --git a/Kyoo/Tasks/CreateDatabase.cs b/Kyoo/Tasks/CreateDatabase.cs index bc6e00df..83cbbc46 100644 --- a/Kyoo/Tasks/CreateDatabase.cs +++ b/Kyoo/Tasks/CreateDatabase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -49,5 +50,15 @@ namespace Kyoo.Tasks } return Task.CompletedTask; } + + public IEnumerable GetPossibleParameters() + { + return null; + } + + public int? Progress() + { + return null; + } } } \ No newline at end of file diff --git a/Kyoo/Tasks/PluginLoader.cs b/Kyoo/Tasks/PluginLoader.cs index af610cfe..a174caa5 100644 --- a/Kyoo/Tasks/PluginLoader.cs +++ b/Kyoo/Tasks/PluginLoader.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Kyoo.Controllers; @@ -22,5 +23,15 @@ namespace Kyoo.Tasks pluginManager.ReloadPlugins(); return Task.CompletedTask; } + + public IEnumerable GetPossibleParameters() + { + return null; + } + + public int? Progress() + { + return null; + } } } \ No newline at end of file diff --git a/Kyoo/Views/API/TaskAPI.cs b/Kyoo/Views/API/TaskAPI.cs index 7de23d36..887cd567 100644 --- a/Kyoo/Views/API/TaskAPI.cs +++ b/Kyoo/Views/API/TaskAPI.cs @@ -17,7 +17,7 @@ namespace Kyoo.Api [HttpGet("{taskSlug}/{args?}")] - // [Authorize(Policy="Admin")] + [Authorize(Policy="Admin")] public IActionResult RunTask(string taskSlug, string args = null) { if (_taskManager.StartTask(taskSlug, args))