Sha256: 1d5effacc194e28da91f5c6e30ba814ed65fba5a7d51b3ca3d7b9b5eb3a613a4
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require "active_support/concern" module RocketJob module Plugins # 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. module ThrottleDependentJobs extend ActiveSupport::Concern included do field :dependent_jobs, type: Array, class_attribute: true, user_editable: true, copy_on_restart: true define_throttle :dependent_job_exists? define_batch_throttle :dependent_job_exists? if respond_to?(:define_batch_throttle) end private # Checks if there are any dependent jobs are running def dependent_job_exists? 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rocketjob-6.0.0 | lib/rocket_job/plugins/throttle_dependent_jobs.rb |