Class: Blender::Driver::SerfAsync

Inherits:
Serf
  • Object
show all
Defined in:
lib/blender/drivers/serf_async.rb

Instance Attribute Summary

Attributes inherited from Serf

#concurrency, #filter_by, #filter_tag

Instance Method Summary collapse

Methods inherited from Serf

#execute, #exit_status, #initialize, #query_opts, #serf_query

Constructor Details

This class inherits a constructor from Blender::Driver::Serf

Instance Method Details

#dup_command(cmd, payload) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/blender/drivers/serf_async.rb', line 28

def dup_command(cmd, payload)
  Blender::Task::Serf::SerfQuery.new(
    cmd.query,
    payload,
    cmd.timeout,
    cmd.noack
  )
end

#extract_status!(res) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/blender/drivers/serf_async.rb', line 71

def extract_status!(res)
  payload = JSON.parse(res['Payload'])
  unless payload['code'].zero?
    raise RuntimeError, "non zero query response code: #{res}"
  end
  Blender::Log.debug("Payload: #{payload['result'].inspect}")
  payload['result']['status']
end

#finished?(cmd, host) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/blender/drivers/serf_async.rb', line 45

def finished?(cmd, host)
  Blender::Log.debug("Checking for status")
  resps = serf_query(dup_command(cmd, 'check'), host)
  Blender::Log.debug("Responses: #{resps.inspect}")
  Blender::Log.debug("Status:#{extract_status!(resps.first)}")
  extract_status!(resps.first) == 'finished'
end

#reap!(cmd, host) ⇒ Object



53
54
55
56
# File 'lib/blender/drivers/serf_async.rb', line 53

def reap!(cmd, host)
  resps = serf_query(dup_command(cmd, 'reap'), host)
  extract_status!(resps.first) == 'success'
end

#run_command(command, host) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/blender/drivers/serf_async.rb', line 58

def run_command(command, host)
  begin
    start!(command, host)
    until finished?(command, host)
      sleep 10
    end
    reap!(command, host)
    ExecOutput.new(0, '', '')
  rescue StandardError => e
    ExecOutput.new( -1, '', e.message + e.backtrace.join("\n"))
  end
end

#start!(cmd, host) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/blender/drivers/serf_async.rb', line 37

def start!(cmd, host)
  resps = serf_query(dup_command(cmd, 'start'), host)
  status = extract_status!(resps.first)
  unless status == 'success'
    raise RuntimeError, "Failed to start async serf job. Status = #{status}"
  end
end