module HydroponicBean::Data
Public Instance Methods
create_job(pri, delay, ttr, data)
click to toggle source
# File lib/hydroponic_bean/data.rb, line 73 def create_job(pri, delay, ttr, data) job = Job.new(current_tube, pri, delay, ttr, data) HydroponicBean.jobs.push(job) return job end
current_tube()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 59 def current_tube HydroponicBean.tubes[current_tube_name] end
current_tube_name()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 55 def current_tube_name @current_tube_name ||= 'default' end
deadline_soon?()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 81 def deadline_soon? HydroponicBean.update_time! watched_tubes.map(&:reserved_jobs).flatten.select do |job| job.reserved_by == self end.sort_by(&:ttr_left).first&.deadline_soon? end
reservable_jobs()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 93 def reservable_jobs watched_tubes.reject(&:paused?).map(&:ready_jobs).flatten.sort_by(&:created_at).sort_by(&:pri) end
reserve_job()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 88 def reserve_job HydroponicBean.update_time! reservable_jobs.first&.reserve(self) end
stats()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 116 def stats { 'current-jobs-urgent' => HydroponicBean.jobs.select(&:urgent?).count, 'current-jobs-ready' => HydroponicBean.jobs.select(&:ready?).count, 'current-jobs-reserved' => HydroponicBean.jobs.select(&:reserved?).count, 'current-jobs-delayed' => HydroponicBean.jobs.select(&:delayed?).count, 'current-jobs-buried' => HydroponicBean.jobs.select(&:buried?).count, 'total-jobs' => HydroponicBean.jobs.count, 'current-tubes' => HydroponicBean.tubes.count, 'current-connections' => HydroponicBean.connections.count, 'current-producers' => HydroponicBean.connections.select(&:produced?).count, 'current-workers' => HydroponicBean.connections.select(&:workers?).count, 'current-waiting' => HydroponicBean.connections.select(&:waiting?).count, }.merge(Hash[HydroponicBean.commands.map{|k, v| ["cmd-#{k}", v]}]) end
wait_for_job(timeout)
click to toggle source
# File lib/hydroponic_bean/data.rb, line 97 def wait_for_job(timeout) self.waiting = true if timeout == 0 return reserve_job else timeout = [0, timeout].max Timeout.timeout(timeout) do while !(job = reserve_job) sleep 0.49 end return job end end rescue Timeout::Error return nil ensure self.waiting = false end
watched_tube_names()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 63 def watched_tube_names @watched_tube_names ||= ['default'] end
watched_tubes()
click to toggle source
# File lib/hydroponic_bean/data.rb, line 67 def watched_tubes watched_tube_names.map do |name| HydroponicBean.tubes[name] end end