Class: Khronos::Server::Runner

Inherits:
GirlFriday::WorkQueue
  • Object
show all
Defined in:
lib/khronos/server/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
16
# File 'lib/khronos/server/runner.rb', line 11

def initialize(*args)
  @queue = self
  super(*args) do |schedule|
    self.process(schedule)
  end
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



9
10
11
# File 'lib/khronos/server/runner.rb', line 9

def queue
  @queue
end

Instance Method Details

#calculate_recurrency!(schedule) ⇒ Object



37
38
39
# File 'lib/khronos/server/runner.rb', line 37

def calculate_recurrency!(schedule)
  RestClient.put(scheduler_route('/task'), :id => schedule['id'], :patch => true)
end

#enqueue(schedule) ⇒ Object



18
19
20
# File 'lib/khronos/server/runner.rb', line 18

def enqueue(schedule)
  @queue.push(schedule.to_json)
end

#log_schedule!(schedule_log) ⇒ Object



41
42
43
# File 'lib/khronos/server/runner.rb', line 41

def log_schedule!(schedule_log)
  RestClient.post( scheduler_route('/schedule/log'), schedule_log )
end

#process(json) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/khronos/server/runner.rb', line 22

def process(json)
  schedule = JSON.parse(json)
  schedule_log = { :started_at => Time.now, :schedule_id => schedule['id'] }

  response = RestClient.get(schedule['task_url'])
  schedule_log[:status_code] = response.code

rescue RestClient::Exception => e
  schedule_log[:status_code] = e.http_code

ensure
  log_schedule!(schedule_log)
  calculate_recurrency!(schedule) if schedule['recurrency'].to_i > 0
end