Class: BBK::App::Middlewares::SelfKiller
- Inherits:
-
Object
- Object
- BBK::App::Middlewares::SelfKiller
- Defined in:
- lib/bbk/app/middlewares/self_killer.rb
Constant Summary collapse
- SELF_KILLER_LOG_INTERVAL =
300
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#stop_time ⇒ Object
readonly
Returns the value of attribute stop_time.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #build(app) ⇒ Object
- #call(msg) ⇒ Object
-
#initialize(dispatcher, delay: 10 * 60, threshold: 10_000, logger: ::Logger.new(STDOUT)) ⇒ SelfKiller
constructor
A new instance of SelfKiller.
Constructor Details
#initialize(dispatcher, delay: 10 * 60, threshold: 10_000, logger: ::Logger.new(STDOUT)) ⇒ SelfKiller
Returns a new instance of SelfKiller.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 11 def initialize(dispatcher, delay: 10 * 60, threshold: 10_000, logger: ::Logger.new(STDOUT)) @dispatcher = dispatcher @threshold = threshold @count = 0 @stop_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + delay @stopping = false @logger = logger @logger.info "[SelfKiller] Initializing: #{@count}/#{@threshold}" reset_log_timer end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
9 10 11 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 9 def count @count end |
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
9 10 11 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 9 def dispatcher @dispatcher end |
#stop_time ⇒ Object (readonly)
Returns the value of attribute stop_time.
9 10 11 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 9 def stop_time @stop_time end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
9 10 11 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 9 def threshold @threshold end |
Instance Method Details
#build(app) ⇒ Object
22 23 24 25 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 22 def build(app) @app = app self end |
#call(msg) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bbk/app/middlewares/self_killer.rb', line 27 def call(msg) @count += 1 if time_exceed?(@log_timer) @logger.info "[SelfKiller] Threshold status: #{@count}/#{@threshold}, delayed: #{!time_exceed?}" reset_log_timer end close_dispatcher if stop? @app.call(msg) end |