Class: DeployPin::Task
- Inherits:
-
Object
- Object
- DeployPin::Task
- Extended by:
- ParallelWrapper
- Includes:
- ParallelWrapper
- Defined in:
- lib/deploy_pin/task.rb
Overview
:reek:TooManyMethods
Constant Summary
Constants included from ParallelWrapper
ParallelWrapper::PARALLEL_PREFIX
Instance Attribute Summary collapse
-
#affected_areas ⇒ Object
readonly
Returns the value of attribute affected_areas.
-
#explicit_timeout ⇒ Object
readonly
Returns the value of attribute explicit_timeout.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#recurring ⇒ Object
readonly
Returns the value of attribute recurring.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
for sorting.
- #details ⇒ Object
- #done? ⇒ Boolean
-
#each_line(&block) ⇒ Object
:reek:TooManyStatements.
- #eql?(other) ⇒ Boolean
- #increment_progress!(incrementor) ⇒ Object
-
#initialize(file) ⇒ Task
constructor
A new instance of Task.
- #mark ⇒ Object
-
#parse ⇒ Object
:reek:TooManyStatements.
- #prepare ⇒ Object
- #record ⇒ Object
- #run ⇒ Object
- #save_progress!(value) ⇒ Object
- #sorting_key ⇒ Object
- #under_timeout? ⇒ Boolean
- #unreachable_future ⇒ Object
Methods included from ParallelWrapper
method_missing, respond_to_missing?
Constructor Details
#initialize(file) ⇒ Task
Returns a new instance of Task.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deploy_pin/task.rb', line 21 def initialize(file) @file = file @identifier = nil @group = nil @title = '' @affected_areas = '' @script = '' @explicit_timeout = false @parallel = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DeployPin::ParallelWrapper
Instance Attribute Details
#affected_areas ⇒ Object (readonly)
Returns the value of attribute affected_areas.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def affected_areas @affected_areas end |
#explicit_timeout ⇒ Object (readonly)
Returns the value of attribute explicit_timeout.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def explicit_timeout @explicit_timeout end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def file @file end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def group @group end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def identifier @identifier end |
#recurring ⇒ Object (readonly)
Returns the value of attribute recurring.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def recurring @recurring end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def script @script end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/deploy_pin/task.rb', line 10 def title @title end |
Instance Method Details
#<=>(other) ⇒ Object
for sorting
134 135 136 |
# File 'lib/deploy_pin/task.rb', line 134 def <=>(other) sorting_key <=> other.sorting_key end |
#details ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/deploy_pin/task.rb', line 107 def details { identifier:, group:, title:, affected_areas: } end |
#done? ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/deploy_pin/task.rb', line 66 def done? return if recurring return unless record record.completed_at.present? end |
#each_line(&block) ⇒ Object
:reek:TooManyStatements
99 100 101 102 103 104 105 |
# File 'lib/deploy_pin/task.rb', line 99 def each_line(&block) if file.starts_with?('# no_file_task') file.each_line(&block) else File.foreach(file, &block) end end |
#eql?(other) ⇒ Boolean
116 117 118 119 |
# File 'lib/deploy_pin/task.rb', line 116 def eql?(other) # same script & different identifier script == other.script && identifier != other.identifier end |
#increment_progress!(incrementor) ⇒ Object
54 55 56 57 58 |
# File 'lib/deploy_pin/task.rb', line 54 def increment_progress!(incrementor) raise NotImplementedError, 'Recurring tasks do not support progress yet.' if recurring record.increment!(:progress, incrementor) end |
#mark ⇒ Object
47 48 49 50 51 52 |
# File 'lib/deploy_pin/task.rb', line 47 def mark return if recurring # store record in the DB record.update(completed_at: Time.current) end |
#parse ⇒ Object
:reek:TooManyStatements
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/deploy_pin/task.rb', line 78 def parse # rubocop:disable Metrics/MethodLength each_line do |line| case line.strip when /\A# (-?\d+):(\w+):?(recurring)?/ @identifier = Regexp.last_match(1).to_i @group = Regexp.last_match(2) @recurring = Regexp.last_match(3) when /\A# task_title:(.+)/ @title = Regexp.last_match(1).strip when /\A# affected_areas:(.+)/ @affected_areas = Regexp.last_match(1).strip when /\A[^#].*/ @script += line @explicit_timeout = true if line =~ /Database.execute_with_timeout.*/ @parallel = true if line =~ /[Pp]arallel.*/ end end end |
#prepare ⇒ Object
41 42 43 44 45 |
# File 'lib/deploy_pin/task.rb', line 41 def prepare return if recurring DeployPin::Record.create(uuid: identifier) unless record end |
#record ⇒ Object
37 38 39 |
# File 'lib/deploy_pin/task.rb', line 37 def record DeployPin::Record.find_by(uuid: identifier) end |
#run ⇒ Object
32 33 34 35 |
# File 'lib/deploy_pin/task.rb', line 32 def run # eval script eval(script) end |
#save_progress!(value) ⇒ Object
60 61 62 63 64 |
# File 'lib/deploy_pin/task.rb', line 60 def save_progress!(value) raise NotImplementedError, 'Recurring tasks do not support progress yet.' if recurring record.update(progress: value) end |
#sorting_key ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/deploy_pin/task.rb', line 125 def sorting_key if identifier.to_i.negative? [group_index, unreachable_future + identifier] else [group_index, identifier] end end |
#under_timeout? ⇒ Boolean
73 74 75 |
# File 'lib/deploy_pin/task.rb', line 73 def under_timeout? !explicit_timeout? && !parallel? end |
#unreachable_future ⇒ Object
121 122 123 |
# File 'lib/deploy_pin/task.rb', line 121 def unreachable_future 1.year.from_now.to_date.strftime('%Y%m%d%H%M%S').to_i end |