Class: Adminix::Entities::Job
- Inherits:
-
Object
- Object
- Adminix::Entities::Job
- Defined in:
- lib/adminix/entities/job.rb
Constant Summary collapse
- STATUS_IN_QUEUE =
'in_queue'.freeze
- STATUS_COMPLETED =
'completed'.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#script ⇒ Object
Returns the value of attribute script.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #filter_script ⇒ Object
- #in_queue? ⇒ Boolean
-
#initialize(id:, script:) ⇒ Job
constructor
A new instance of Job.
- #perform ⇒ Object
- #to_api ⇒ Object
Constructor Details
#initialize(id:, script:) ⇒ Job
Returns a new instance of Job.
10 11 12 13 14 15 16 17 18 |
# File 'lib/adminix/entities/job.rb', line 10 def initialize(id:, script:) @id = id @script = script @status = STATUS_IN_QUEUE @created_at = Time.now @success = false filter_script end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/adminix/entities/job.rb', line 4 def id @id end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/adminix/entities/job.rb', line 5 def output @output end |
#script ⇒ Object
Returns the value of attribute script.
4 5 6 |
# File 'lib/adminix/entities/job.rb', line 4 def script @script end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/adminix/entities/job.rb', line 5 def status @status end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
5 6 7 |
# File 'lib/adminix/entities/job.rb', line 5 def success @success end |
Instance Method Details
#completed? ⇒ Boolean
31 32 33 |
# File 'lib/adminix/entities/job.rb', line 31 def completed? @status == STATUS_COMPLETED end |
#filter_script ⇒ Object
35 36 37 38 39 |
# File 'lib/adminix/entities/job.rb', line 35 def filter_script ['sudo', 'shutdown', 'kill'].each do |word| @script = @script.gsub('word', '') end end |
#in_queue? ⇒ Boolean
27 28 29 |
# File 'lib/adminix/entities/job.rb', line 27 def in_queue? @status == STATUS_IN_QUEUE end |
#perform ⇒ Object
20 21 22 23 24 25 |
# File 'lib/adminix/entities/job.rb', line 20 def perform @output = `/bin/bash #{Adminix.config.scripts[:run_script]} #{script}` @success = $?.success? @status = STATUS_COMPLETED @completed_at = Time.now end |
#to_api ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/adminix/entities/job.rb', line 41 def to_api { id: @id, status: @status, script: @script, success: @success, output: @output, created_at: @created_at, completed_at: @completed_at } end |