Module: CaptainConfig::SidekiqMiddlewareFactory::SidekiqMiddleware::ClassMethods
- Defined in:
- lib/captain_config/middlewares/sidekiq_middleware_factory.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#last_loaded_at ⇒ Object
readonly
Returns the value of attribute last_loaded_at.
Instance Method Summary collapse
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
22 23 24 |
# File 'lib/captain_config/middlewares/sidekiq_middleware_factory.rb', line 22 def interval @interval end |
#last_loaded_at ⇒ Object (readonly)
Returns the value of attribute last_loaded_at.
22 23 24 |
# File 'lib/captain_config/middlewares/sidekiq_middleware_factory.rb', line 22 def last_loaded_at @last_loaded_at end |
Instance Method Details
#load ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/captain_config/middlewares/sidekiq_middleware_factory.rb', line 34 def load @mutex.synchronize do # The instances of the middleware on each thread call `#needs_load?` # unsynchronized, so they may think a reload is needed when it isn't. return unless needs_load? service = CaptainConfig::Service.last_created_service service&.load @last_loaded_at = Time.now end end |
#needs_load? ⇒ Boolean
30 31 32 |
# File 'lib/captain_config/middlewares/sidekiq_middleware_factory.rb', line 30 def needs_load? (Time.now - @last_loaded_at) >= @interval end |
#setup(interval:) ⇒ Object
24 25 26 27 28 |
# File 'lib/captain_config/middlewares/sidekiq_middleware_factory.rb', line 24 def setup(interval:) @interval = interval @mutex = Mutex.new @last_loaded_at = Time.at(0) end |