Module: RocketJob::Plugins::Job::Throttle
- Extended by:
- ActiveSupport::Concern
- Included in:
- Job
- Defined in:
- lib/rocket_job/plugins/job/throttle.rb
Overview
Rocket Job Throttling Framework.
Example:
# Do not run this job when the MySQL slave delay exceeds 5 minutes.
class MyJob < RocketJob::Job
# Define a custom mysql throttle
# Prevents all jobs of this class from running on the current server.
define_throttle :mysql_throttle_exceeded?
def perform
# ....
end
private
# Returns true if the MySQL slave delay exceeds 5 minutes
def mysql_throttle_exceeded?
status = ActiveRecord::Base.connection.select_one('show slave status')
seconds_delay = Hash(status)['Seconds_Behind_Master'].to_i
seconds_delay >= 300
end
end
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#throttle_filter_class ⇒ Object
Default throttle to use when the throttle is exceeded.
-
#throttle_filter_id ⇒ Object
Filter out only this instance of the job.
Instance Method Details
#throttle_filter_class ⇒ Object
Default throttle to use when the throttle is exceeded. 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.
74 75 76 |
# File 'lib/rocket_job/plugins/job/throttle.rb', line 74 def throttle_filter_class {:_type.nin => [self.class.name]} end |
#throttle_filter_id ⇒ Object
Filter out only this instance of the job. When the throttle has been exceeded this job will be ignored by this server until the next refresh. ‘RocketJob::Config.re_check_seconds` which by default is 60 seconds.
81 82 83 |
# File 'lib/rocket_job/plugins/job/throttle.rb', line 81 def throttle_filter_id {:id.nin => [id]} end |