Class: Honcho::Adapters::Base
- Inherits:
-
Object
- Object
- Honcho::Adapters::Base
- Defined in:
- lib/honcho/adapters/base.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#stopping ⇒ Object
readonly
Returns the value of attribute stopping.
Instance Method Summary collapse
- #check_for_work ⇒ Object
- #commands ⇒ Object
-
#initialize(config:, redis:, runner:) ⇒ Base
constructor
A new instance of Base.
- #name ⇒ Object
- #path ⇒ Object
- #really_stop ⇒ Object
- #run? ⇒ Boolean
- #running? ⇒ Boolean
- #should_stop? ⇒ Boolean
- #start ⇒ Object
- #start_command ⇒ Object
- #stop ⇒ Object
- #stopping? ⇒ Boolean
- #total_count ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(config:, redis:, runner:) ⇒ Base
Returns a new instance of Base.
4 5 6 7 8 9 10 |
# File 'lib/honcho/adapters/base.rb', line 4 def initialize(config:, redis:, runner:) @config = config @redis = redis @runner = runner @running = false @stopping = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/honcho/adapters/base.rb', line 12 def config @config end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
12 13 14 |
# File 'lib/honcho/adapters/base.rb', line 12 def redis @redis end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
12 13 14 |
# File 'lib/honcho/adapters/base.rb', line 12 def runner @runner end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
12 13 14 |
# File 'lib/honcho/adapters/base.rb', line 12 def running @running end |
#stopping ⇒ Object (readonly)
Returns the value of attribute stopping.
12 13 14 |
# File 'lib/honcho/adapters/base.rb', line 12 def stopping @stopping end |
Instance Method Details
#check_for_work ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/honcho/adapters/base.rb', line 18 def check_for_work if run? start else stop end end |
#commands ⇒ Object
30 31 32 |
# File 'lib/honcho/adapters/base.rb', line 30 def commands Array(config['command']) end |
#name ⇒ Object
26 27 28 |
# File 'lib/honcho/adapters/base.rb', line 26 def name config['name'] end |
#path ⇒ Object
34 35 36 |
# File 'lib/honcho/adapters/base.rb', line 34 def path config['path'] end |
#really_stop ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/honcho/adapters/base.rb', line 82 def really_stop @stopping = false return unless running? log(name, "STOPPING\n") running.each do |(pid, wout)| Process.kill('-TERM', pid) wout.close end @running = false end |
#run? ⇒ Boolean
38 39 40 |
# File 'lib/honcho/adapters/base.rb', line 38 def run? work_to_do? || work_being_done? end |
#running? ⇒ Boolean
42 43 44 |
# File 'lib/honcho/adapters/base.rb', line 42 def running? @running != false end |
#should_stop? ⇒ Boolean
78 79 80 |
# File 'lib/honcho/adapters/base.rb', line 78 def should_stop? stopping? && stopping <= 0 end |
#start ⇒ Object
50 51 52 53 54 55 |
# File 'lib/honcho/adapters/base.rb', line 50 def start @stopping = false return if running? log(name, "STARTING\n") @running = start_command end |
#start_command ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/honcho/adapters/base.rb', line 57 def start_command commands.map do |cmd| rout, wout = IO.pipe pid = spawn(path, cmd, wout) Thread.new do log(name, rout.gets) until rout.eof? end [pid, wout] end end |
#stop ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/honcho/adapters/base.rb', line 68 def stop return unless running? if should_stop? really_stop else @stopping ||= stop_delay @stopping -= interval end end |
#stopping? ⇒ Boolean
46 47 48 |
# File 'lib/honcho/adapters/base.rb', line 46 def stopping? @stopping != false end |
#total_count ⇒ Object
93 94 95 |
# File 'lib/honcho/adapters/base.rb', line 93 def total_count queued_count + busy_count end |
#type ⇒ Object
14 15 16 |
# File 'lib/honcho/adapters/base.rb', line 14 def type self.class.name.split(':').last.downcase end |