Class: Semaph::Model::Job
- Inherits:
-
Object
- Object
- Semaph::Model::Job
- Defined in:
- lib/semaph/model/job.rb
Instance Attribute Summary collapse
-
#block_name ⇒ Object
readonly
Returns the value of attribute block_name.
-
#block_state ⇒ Object
readonly
Returns the value of attribute block_state.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#block_icon ⇒ Object
block_state can be waiting/running/done block_result can be passed/failed/canceled/stopped.
- #description ⇒ Object
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(pipeline, raw_block, raw_job) ⇒ Job
constructor
A new instance of Job.
-
#job_icon ⇒ Object
status can be FINISHED/RUNNING result can be PASSED/FAILED/STOPPED.
- #show ⇒ Object
- #stop ⇒ Object
- #write_log(base) ⇒ Object
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_name ⇒ Object (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_state ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/semaph/model/job.rb', line 6 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/semaph/model/job.rb', line 6 def name @name end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
6 7 8 |
# File 'lib/semaph/model/job.rb', line 6 def pipeline @pipeline end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/semaph/model/job.rb', line 6 def result @result end |
#status ⇒ Object (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_icon ⇒ Object
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 |
#description ⇒ Object
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
59 60 61 |
# File 'lib/semaph/model/job.rb', line 59 def failed? @result == "FAILED" end |
#finished? ⇒ Boolean
55 56 57 |
# File 'lib/semaph/model/job.rb', line 55 def finished? @status == "FINISHED" end |
#job_icon ⇒ Object
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 |
#show ⇒ Object
29 30 31 |
# File 'lib/semaph/model/job.rb', line 29 def show pp pipeline.workflow.project.client.job(id) end |
#stop ⇒ Object
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 |