Class: Vx::Worker::UpdateJobStatus

Inherits:
Struct
  • Object
show all
Includes:
Helper::Logger
Defined in:
lib/vx/worker/middlewares/update_job_status.rb

Constant Summary collapse

STARTED =
2
FINISHED =
3
BROKEN =
4
FAILED =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Logger

#logger

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



7
8
9
# File 'lib/vx/worker/middlewares/update_job_status.rb', line 7

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vx/worker/middlewares/update_job_status.rb', line 16

def call(env)

  update_status env.job, STARTED
  rs = -1
  begin
    rs = app.call env
  rescue ::Timeout::Error => e
    env.job.add_to_output("\n\nERROR: #{e.message}\n")
  rescue ::Exception => e
    env.job.add_to_output("\n\nERROR: #{e.inspect}\n")
    logger.error("ERROR: #{e.inspect}\n    BACKTRACE:\n#{e.backtrace.map{|i| "    #{i}" }.join("\n")}")
    Common::ErrorNotifier.notify(e)
  end

  msg = "\nDone. Your build exited with %s.\n"
  env.job.add_to_output(msg % rs.abs)

  case
  when rs == 0
    update_status env.job, FINISHED
  when rs > 0
    update_status env.job, BROKEN
  when rs < 0
    update_status env.job, FAILED
  end

  rs
end