class HydroponicBean::Tube
Attributes
jobs[R]
name[R]
stats[R]
Public Class Methods
new(name)
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 5 def initialize(name) @name = name @jobs = [] @paused_at = nil @stats = { 'cmd-delete' => 0, 'cmd-pause-tube' => 0, 'pause' => 0, } end
Public Instance Methods
_pause_time_left()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 104 def _pause_time_left [stats['pause'] - (Time.now.utc - @paused_at).to_i, 0].max end
buried_jobs()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 67 def buried_jobs; jobs.select(&:buried?); end
current_jobs_buried()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 25 def current_jobs_buried; jobs.select(&:buried?).count; end
current_jobs_delayed()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 24 def current_jobs_delayed; jobs.select(&:delayed?).count; end
current_jobs_ready()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 22 def current_jobs_ready; jobs.select(&:ready?).count; end
current_jobs_reserved()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 23 def current_jobs_reserved; jobs.select(&:reserved?).count; end
current_jobs_urgent()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 21 def current_jobs_urgent; jobs.select(&:urgent?).count; end
current_using()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 27 def current_using HydroponicBean.connections.select{|c| c.current_tube_name == name}.count end
current_waiting()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 37 def current_waiting HydroponicBean.connections.select do |c| c.waiting? && c.watched_tube_names.include?(name) end.count end
current_watching()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 31 def current_watching HydroponicBean.connections.select do |c| c.watched_tube_names.include?(name) end.count end
delayed_jobs()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 68 def delayed_jobs; jobs.select(&:delayed?).sort_by(&:time_left); end
job_deleted!()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 108 def job_deleted! stats['cmd-delete'] += 1 end
kick(bound)
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 70 def kick(bound) initial_bound = bound while bound > 0 if buried_jobs.count > 0 buried_jobs.first.kick bound -= 1 elsif delayed_jobs.count > 0 delayed_jobs.first.kick bound -= 1 else return initial_bound - bound end end return initial_bound end
pause(delay)
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 59 def pause(delay) delay = delay.to_i stats['pause'] = delay stats['cmd-pause-tube'] += 1 end
pause_time_left()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 96 def pause_time_left if paused? return _pause_time_left else return 0 end end
paused?()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 86 def paused? if !@paused_at || _pause_time_left == 0 stats['pause'] = 0 @paused_at = nil return false else return true end end
push(job)
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 16 def push(job) @jobs.push(job) self end
ready_jobs()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 65 def ready_jobs; jobs.select(&:ready?); end
reserved_jobs()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 66 def reserved_jobs; jobs.select(&:reserved?); end
serialize_stats()
click to toggle source
# File lib/hydroponic_bean/tube.rb, line 43 def serialize_stats { 'name' => name, 'current-jobs-urgent' => current_jobs_urgent, 'current-jobs-ready' => current_jobs_ready, 'current-jobs-reserved' => current_jobs_reserved, 'current-jobs-delayed' => current_jobs_delayed, 'current-jobs-buried' => current_jobs_buried, 'total-jobs' => jobs.count, 'current-using' => current_using, 'current-waiting' => current_waiting, 'current-watching' => current_watching, 'pause-time-left' => pause_time_left, }.merge(stats) end