module RocketJob::Plugins::ThrottleDependentJobs
Prevent this job from starting, or a batch slice from starting if the dependent jobs are running.
Features:
-
Ensures dependent jobs won’t run
When the throttle has been exceeded all jobs of this class will be ignored until the next refresh. ‘RocketJob::Config::re_check_seconds` which by default is 60 seconds.
Public Instance Methods
depends_on_job(*jobs)
click to toggle source
# File lib/rocket_job/plugins/throttle_dependent_jobs.rb, line 21 def depends_on_job(*jobs) self.dependent_jobs = Array(jobs).collect(&:to_s) end
Private Instance Methods
dependent_jobs_running?()
click to toggle source
Checks if there are any dependent jobs are running
# File lib/rocket_job/plugins/throttle_dependent_jobs.rb, line 29 def dependent_jobs_running? return false if dependent_jobs.blank? jobs_count = RocketJob::Job.running.where(:_type.in => dependent_jobs).count return false if jobs_count.zero? logger.info( message: "#{jobs_count} Dependent Jobs are running from #{dependent_jobs.join(', ')}", metric: "#{self.class.name}/dependent_jobs_throttle" ) true end