From f3f398f7829c4b309b7a4056809ef2e6b0c701e9 Mon Sep 17 00:00:00 2001 From: Joel Goransson Date: Fri, 24 Mar 2023 15:06:05 +1100 Subject: [PATCH] Add JobCount method to MonitoringApi to get count of jobs in any state --- src/Hangfire.Core/Storage/IMonitoringApi.cs | 1 + src/Hangfire.Core/Storage/JobStorageMonitor.cs | 1 + src/Hangfire.SqlServer/SqlServerMonitoringApi.cs | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/Hangfire.Core/Storage/IMonitoringApi.cs b/src/Hangfire.Core/Storage/IMonitoringApi.cs index 31a8939f6..2a79a5888 100644 --- a/src/Hangfire.Core/Storage/IMonitoringApi.cs +++ b/src/Hangfire.Core/Storage/IMonitoringApi.cs @@ -35,6 +35,7 @@ public interface IMonitoringApi JobList FailedJobs(int from, int count); JobList DeletedJobs(int from, int count); + long JobCount(string stateName); long ScheduledCount(); long EnqueuedCount(string queue); long FetchedCount(string queue); diff --git a/src/Hangfire.Core/Storage/JobStorageMonitor.cs b/src/Hangfire.Core/Storage/JobStorageMonitor.cs index 8d749e4d1..da3dc09bc 100644 --- a/src/Hangfire.Core/Storage/JobStorageMonitor.cs +++ b/src/Hangfire.Core/Storage/JobStorageMonitor.cs @@ -39,6 +39,7 @@ public virtual JobList AwaitingJobs(int from, int count) throw JobStorageFeatures.GetNotSupportedException(JobStorageFeatures.Monitoring.AwaitingJobs); } + public abstract long JobCount(string stateName); public abstract long ScheduledCount(); public abstract long EnqueuedCount(string queue); public abstract long FetchedCount(string queue); diff --git a/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs b/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs index ee589dae5..c3cad107c 100644 --- a/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs +++ b/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs @@ -42,6 +42,11 @@ public SqlServerMonitoringApi([NotNull] SqlServerStorage storage, int? jobListLi _jobListLimit = jobListLimit; } + public override long JobCount(string stateName) + { + return UseConnection(connection => GetNumberOfJobsByStateName(connection, stateName)); + } + public override long ScheduledCount() { return UseConnection(connection =>