Class: Semaph::Model::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/semaph/model/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, raw_block, raw_job) ⇒ Job

Returns a new instance of Job.



17
18
19
20
21
22
23
# File 'lib/semaph/model/job.rb', line 17

def initialize(pipeline, raw_block, raw_job)
  @pipeline = pipeline
  @raw_block = raw_block
  @raw_job = raw_job
  assign_from_job(raw_job)
  assign_from_block(raw_block)
end

Instance Attribute Details

#block_nameObject (readonly)

Returns the value of attribute block_name.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def block_name
  @block_name
end

#block_stateObject (readonly)

Returns the value of attribute block_state.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def block_state
  @block_state
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def name
  @name
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def pipeline
  @pipeline
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/semaph/model/job.rb', line 6

def status
  @status
end

Instance Method Details

#block_iconObject

block_state can be waiting/running/done block_result can be passed/failed/canceled/stopped



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/semaph/model/job.rb', line 65

def block_icon
  return "🟠" if @block_state == "waiting"

  return "🔵" if @block_state == "running"

  return "⚪" if @block_result == "canceled"

  return "â›”" if @block_result == "stopped"

  return "🟢" if @block_result == "passed"

  "🔴"
end

#descriptionObject



46
47
48
49
50
51
52
53
# File 'lib/semaph/model/job.rb', line 46

def description
  [
    block_icon,
    @block_name,
    job_icon,
    @name,
  ].compact.join(" ")
end

#failed?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/semaph/model/job.rb', line 59

def failed?
  @result == "FAILED"
end

#finished?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/semaph/model/job.rb', line 55

def finished?
  @status == "FINISHED"
end

#job_iconObject

status can be FINISHED/RUNNING result can be PASSED/FAILED/STOPPED



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/semaph/model/job.rb', line 81

def job_icon
  return nil unless @status

  return "🔵" unless @status == "FINISHED"

  return "â›”" if @result == "STOPPED"

  return "🟢" if @result == "PASSED"

  "🔴"
end

#showObject



29
30
31
# File 'lib/semaph/model/job.rb', line 29

def show
  pp pipeline.workflow.project.client.job(id)
end

#stopObject



25
26
27
# File 'lib/semaph/model/job.rb', line 25

def stop
  pipeline.workflow.project.client.stop_job(id)
end

#write_log(base) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/semaph/model/job.rb', line 33

def write_log(base)
  FileUtils.mkdir_p(base)
  filename = "#{base}/#{id}.log"
  return filename if File.exist?(filename)

  puts "retrieving log for job #{id}"
  File.open(filename, "w") do |file|
    file.puts pipeline.workflow.project.client.job_log(id)
  end

  filename
end