Ejemplo n.º 1
0
        public static void PurgeOrfanJobsExceptList(this IMonitoringApi monitor, List <string> exceptions)
        {
            var toDelete = new List <string>();

            foreach (QueueWithTopEnqueuedJobsDto queue in monitor.Queues())
            {
                for (var i = 0; i < Math.Ceiling(queue.Length / 1000d); i++)
                {
                    monitor.EnqueuedJobs(queue.Name, 1000 * i, 1000)
                    .ForEach(x =>
                    {
                        if (!exceptions.Contains(x.Key))
                        {
                            toDelete.Add(x.Key);
                        }
                        else
                        {
                            Console.WriteLine("x.Key " + x.Key + "  remains.");
                        }
                    }
                             );
                }
            }

            foreach (var jobId in toDelete)
            {
                BackgroundJob.Delete(jobId);
            }
        }
Ejemplo n.º 2
0
        // https://github.com/HangfireIO/Hangfire/issues/394#issuecomment-179924221
        public static void PurgeJobs(this IMonitoringApi monitoringApi)
        {
            var toDelete = new List <string>();

            foreach (var queue in monitoringApi.Queues())
            {
                for (var i = 0; i < Math.Ceiling(queue.Length / 1000d); i++)
                {
                    toDelete.AddRange(monitoringApi.EnqueuedJobs(queue.Name, 1000 * i, 1000).Select(x => x.Key));
                }
            }

            foreach (var jobId in toDelete)
            {
                BackgroundJob.Delete(jobId);
            }
        }
Ejemplo n.º 3
0
        public static void PurgeJobs(this IMonitoringApi monitor)
        {
            var toDelete = new List <string>();

            foreach (QueueWithTopEnqueuedJobsDto queue in monitor.Queues())
            {
                for (var i = 0; i < Math.Ceiling(queue.Length / 1000d); i++)
                {
                    monitor.EnqueuedJobs(queue.Name, 1000 * i, 1000)
                    .ForEach(x => toDelete.Add(x.Key));
                }
            }

            foreach (var jobId in toDelete)
            {
                BackgroundJob.Delete(jobId);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// check Job is enqueued or processing
        /// </summary>
        /// <param name="actionName">full action name</param>
        /// <returns></returns>
        public static bool IsRunning(IMonitoringApi api, string actionName)
        {
            var queues = api.Queues();

            foreach (var queue in queues)
            {
                var queueName     = queue.Name;
                var enqueuedCount = Convert.ToInt32(api.EnqueuedCount(queueName));
                var enqueuedJobs  = api.EnqueuedJobs(queueName, 0, enqueuedCount);

                if (enqueuedJobs.Any(job => job.Value.Job.Method.GetFullActionName() == actionName))
                {
                    return(true);
                }
            }

            var processingCount = Convert.ToInt32(api.ProcessingCount());
            var processingJobs  = api.ProcessingJobs(0, processingCount);

            return(processingJobs.Any(job => job.Value.Job.Method.GetFullActionName() == actionName));
        }