diff --git a/Shoko.Server/API/v3/Controllers/QueueController.cs b/Shoko.Server/API/v3/Controllers/QueueController.cs index e8d06bf7f..432181058 100644 --- a/Shoko.Server/API/v3/Controllers/QueueController.cs +++ b/Shoko.Server/API/v3/Controllers/QueueController.cs @@ -123,7 +123,7 @@ public async Task Clear() var offset = (page - 1) * pageSize; // simplified from (page - 1) * pageSize + pageSize - if (page * pageSize <= _settingsProvider.GetSettings().Quartz.WaitingCacheSize) + if (page * pageSize <= _settingsProvider.GetSettings().Quartz.WaitingCacheSize && showAll) { var results = _queueHandler.GetExecutingJobs().Skip(offset).Take(pageSize).ToList(); if (pageSize - results.Count > 0) diff --git a/Shoko.Server/Scheduling/ThreadPooledJobStore.cs b/Shoko.Server/Scheduling/ThreadPooledJobStore.cs index 07b54913d..636da7cea 100644 --- a/Shoko.Server/Scheduling/ThreadPooledJobStore.cs +++ b/Shoko.Server/Scheduling/ThreadPooledJobStore.cs @@ -408,23 +408,21 @@ protected override async Task TriggerFired(ConnectionAndTran public Task GetWaitingTriggersCount() { - return ExecuteInNonManagedTXLock(LockTriggerAccess, async conn => await GetWaitingTriggersCount(conn), new CancellationToken()); + return ExecuteInNonManagedTXLock(LockTriggerAccess, async conn => await GetWaitingTriggersCount(conn, GetTypes()), new CancellationToken()); } - private Task GetWaitingTriggersCount(ConnectionAndTransactionHolder conn, CancellationToken cancellationToken = new CancellationToken()) + private Task GetWaitingTriggersCount(ConnectionAndTransactionHolder conn, JobTypes types, CancellationToken cancellationToken = new CancellationToken()) { - var types = GetTypes(); return Delegate.SelectWaitingTriggerCount(conn, NoLaterThan, NoEarlierThan, types, cancellationToken); } public Task GetBlockedTriggersCount() { - return ExecuteInNonManagedTXLock(LockTriggerAccess, async conn => await GetBlockedTriggersCount(conn), new CancellationToken()); + return ExecuteInNonManagedTXLock(LockTriggerAccess, async conn => await GetBlockedTriggersCount(conn, GetTypes()), new CancellationToken()); } - private Task GetBlockedTriggersCount(ConnectionAndTransactionHolder conn, CancellationToken cancellationToken = new CancellationToken()) + private Task GetBlockedTriggersCount(ConnectionAndTransactionHolder conn, JobTypes types, CancellationToken cancellationToken = new CancellationToken()) { - var types = GetTypes(); return Delegate.SelectBlockedTriggerCount(conn, _typeLoadHelper, NoLaterThan, NoEarlierThan, types, cancellationToken); } @@ -477,6 +475,7 @@ public Task> GetJobs(int maxCount, int offset, bool excludeBlock }; }).OrderBy(a => a.StartTime)); } + else offset -= _executingJobs.Count; } if (maxCount - result.Count <= 0) return result; @@ -518,8 +517,9 @@ private async Task JobStoringQueueEvents(ConnectionAndTransactionHolder conn, IJ { try { - var waitingTriggerCount = await GetWaitingTriggersCount(conn, cancellationToken); - var blockedTriggerCount = await GetBlockedTriggersCount(conn, cancellationToken); + var types = GetTypes(); + var waitingTriggerCount = await GetWaitingTriggersCount(conn, types, cancellationToken); + var blockedTriggerCount = await GetBlockedTriggersCount(conn, types, cancellationToken); if (_threadPoolSize == 0) _threadPoolSize = await GetThreadPoolSize(cancellationToken); var executing = GetExecutingQueueItems(); var waiting = await GetJobs(conn, _settingsProvider.GetSettings().Quartz.WaitingCacheSize, _threadPoolSize, false, cancellationToken); @@ -546,8 +546,9 @@ private async Task JobFiringQueueEvents(ConnectionAndTransactionHolder conn, IOp try { lock(_executingJobs) _executingJobs[jobDetail.Key] = (jobDetail, trigger.StartTimeUtc.LocalDateTime); - var waitingTriggerCount = await GetWaitingTriggersCount(conn, cancellationToken); - var blockedTriggerCount = await GetBlockedTriggersCount(conn, cancellationToken); + var types = GetTypes(); + var waitingTriggerCount = await GetWaitingTriggersCount(conn, types, cancellationToken); + var blockedTriggerCount = await GetBlockedTriggersCount(conn, types, cancellationToken); if (_threadPoolSize == 0) _threadPoolSize = await GetThreadPoolSize(cancellationToken); var executing = GetExecutingQueueItems(); var waiting = await GetJobs(conn, _settingsProvider.GetSettings().Quartz.WaitingCacheSize, _threadPoolSize, false, cancellationToken); @@ -595,11 +596,13 @@ private async Task JobCompletedQueueEvents(ConnectionAndTransactionHolder conn, { // this runs before the states have been updated, so things that were blocked for concurrency are still blocked at this point lock(_executingJobs) _executingJobs.Remove(jobDetail.Key); - var waitingTriggerCount = await GetWaitingTriggersCount(conn, cancellationToken); - var blockedTriggerCount = await GetBlockedTriggersCount(conn, cancellationToken); + var types = GetTypes(); + var waitingTriggerCount = await GetWaitingTriggersCount(conn, types, cancellationToken); + var blockedTriggerCount = await GetBlockedTriggersCount(conn, types, cancellationToken); if (_threadPoolSize == 0) _threadPoolSize = await GetThreadPoolSize(cancellationToken); var executing = GetExecutingQueueItems(); var waiting = await GetJobs(conn, _settingsProvider.GetSettings().Quartz.WaitingCacheSize, _threadPoolSize, false, cancellationToken); + _queueStateEventHandler.OnJobCompleted(jobDetail, new QueueStateContext { ThreadCount = _threadPoolSize,