Class: Isono::NodeModules::JobCollector::Dispatch
- Inherits:
-
Object
- Object
- Isono::NodeModules::JobCollector::Dispatch
- Defined in:
- lib/isono/node_modules/job_collector.rb
Instance Method Summary collapse
- #call(req, res) ⇒ Object
-
#initialize(retry_count, wait_time_sec) ⇒ Dispatch
constructor
A new instance of Dispatch.
- #record ⇒ Object
Constructor Details
#initialize(retry_count, wait_time_sec) ⇒ Dispatch
Returns a new instance of Dispatch.
26 27 28 29 30 |
# File 'lib/isono/node_modules/job_collector.rb', line 26 def initialize(retry_count, wait_time_sec) @retry_count = retry_count @wait_time_sec = wait_time_sec end |
Instance Method Details
#call(req, res) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/isono/node_modules/job_collector.rb', line 51 def call(req, res) @req, @res = req, res raise Rack::UnknownMethodError if @req.command == 'call' m = self.method(@req.command) raise Rack::UnknownMethodError if m.nil? ret = m.call @res.response(nil) if @res.responded? end |
#record ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/isono/node_modules/job_collector.rb', line 32 def record params = @req.args[0] params[:node_id]=@req.sender retry_count = 0 begin job = Models::JobState.find_or_create(:job_id=>params[:job_id]) rescue Sequel::DatabaseError, Sequel::DatabaseConnectionError => e if retry_count <= @retry_count.to_i retry_count += 1 sleep @wait_time_sec.to_i retry else raise e end end job.set_fields(params, [:parent_job_id, :session_id, :node_id, :state, :started_at, :finished_at, :job_name]).save_changes end |