Job Scheduler - Detect if Job is running by Job Class Name

Developer Space

Developer Space
Want to extend the Telligent Evolution platform? Collaborate with other developers and product experts here.

Job Scheduler - Detect if Job is running by Job Class Name

This question is answered

Is there a way to tell (via C# code) if a job with a certain class name  is currently executing?

Verified Answer
  • If anyone needs this, here is what I was able to come up with - This will return the # of currently executing jobs of the specified Type.

            public static int GetCurrentlyExecutingJobCount(Type jobType)
            {
                IScheduler scheduler = JobsManager.GetScheduler();
                var jobs = scheduler.GetCurrentlyExecutingJobs();
                var jobCount = 0;
    
                foreach (JobExecutionContext job in jobs)
                {
                    if (job.JobDetail.JobType.FullName.Equals(jobType.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        jobCount++;
                    }
                }
    
                //
                return jobCount;
            }
  • One more variation - this will get you any dynamically scheduled jobs (as opposed to the ones defined in tasks.config).  The code is virtually identical aside from the type of IScheduler object you request.

            public static int GetCurrentlyExecutingJobCount(Type jobType)
            {
                IScheduler scheduler = JobsManager.GetDynamicScheduler();
                var jobs = scheduler.GetCurrentlyExecutingJobs();
                var jobCount = 0;
    
                foreach (JobExecutionContext job in jobs)
                {
                    if (job.JobDetail.JobType.FullName.Equals(jobType.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        jobCount++;
                    }
                }
                return jobCount;
            }
All Replies
  • If anyone needs this, here is what I was able to come up with - This will return the # of currently executing jobs of the specified Type.

            public static int GetCurrentlyExecutingJobCount(Type jobType)
            {
                IScheduler scheduler = JobsManager.GetScheduler();
                var jobs = scheduler.GetCurrentlyExecutingJobs();
                var jobCount = 0;
    
                foreach (JobExecutionContext job in jobs)
                {
                    if (job.JobDetail.JobType.FullName.Equals(jobType.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        jobCount++;
                    }
                }
    
                //
                return jobCount;
            }
  • One more variation - this will get you any dynamically scheduled jobs (as opposed to the ones defined in tasks.config).  The code is virtually identical aside from the type of IScheduler object you request.

            public static int GetCurrentlyExecutingJobCount(Type jobType)
            {
                IScheduler scheduler = JobsManager.GetDynamicScheduler();
                var jobs = scheduler.GetCurrentlyExecutingJobs();
                var jobCount = 0;
    
                foreach (JobExecutionContext job in jobs)
                {
                    if (job.JobDetail.JobType.FullName.Equals(jobType.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        jobCount++;
                    }
                }
                return jobCount;
            }