Class: Vx::Worker::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Logger

#logger

Constructor Details

#initialize(perform_job_message) ⇒ Job

Returns a new instance of Job.



12
13
14
15
16
# File 'lib/vx/worker/job.rb', line 12

def initialize(perform_job_message)
  @output_counter = 0
  @message        = perform_job_message
  @output         = Common::OutputBuffer.new(&method(:publish_job_log_message))
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/vx/worker/job.rb', line 10

def message
  @message
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/vx/worker/job.rb', line 10

def output
  @output
end

#output_counterObject (readonly)

Returns the value of attribute output_counter.



10
11
12
# File 'lib/vx/worker/job.rb', line 10

def output_counter
  @output_counter
end

Instance Method Details

#add_command_to_output(cmd) ⇒ Object



23
24
25
# File 'lib/vx/worker/job.rb', line 23

def add_command_to_output(cmd)
  add_to_output "$ #{cmd}\n"
end

#add_to_output(str) ⇒ Object



18
19
20
21
# File 'lib/vx/worker/job.rb', line 18

def add_to_output(str)
  output << str
  logger.debug str.strip if logger.level == 0
end

#add_trace_to_output(log) ⇒ Object



27
28
29
# File 'lib/vx/worker/job.rb', line 27

def add_trace_to_output(log)
  add_to_output log.split(/\n/).map{|i| " ===> #{i}\n" }.join
end

#publish_job_log_message(str) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vx/worker/job.rb', line 35

def publish_job_log_message(str)
  @output_counter += 1
  log = Message::JobLog.new(
    build_id: message.id,
    job_id:   message.job_id,
    tm:       output_counter,
    log:      str
  )
  JobLogsConsumer.publish log
  log
end

#releaseObject



31
32
33
# File 'lib/vx/worker/job.rb', line 31

def release
  output.close
end