Class: DeployPin::Task
Constant Summary
ParallelWrapper::PARALLEL_PREFIX
Instance Attribute Summary collapse
Instance Method Summary
collapse
method_missing, respond_to_missing?
Constructor Details
#initialize(file) ⇒ Task
Returns a new instance of Task.
19
20
21
22
23
24
25
26
27
|
# File 'lib/deploy_pin/task.rb', line 19
def initialize(file)
@file = file
@identifier = nil
@group = nil
@title = ''
@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
#explicit_timeout ⇒ Object
Returns the value of attribute explicit_timeout.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def explicit_timeout
@explicit_timeout
end
|
#file ⇒ Object
Returns the value of attribute file.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def file
@file
end
|
#group ⇒ Object
Returns the value of attribute group.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def group
@group
end
|
#identifier ⇒ Object
Returns the value of attribute identifier.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def identifier
@identifier
end
|
#recurring ⇒ Object
Returns the value of attribute recurring.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def recurring
@recurring
end
|
#script ⇒ Object
Returns the value of attribute script.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def script
@script
end
|
#title ⇒ Object
Returns the value of attribute title.
9
10
11
|
# File 'lib/deploy_pin/task.rb', line 9
def title
@title
end
|
Instance Method Details
#<=>(other) ⇒ Object
120
121
122
|
# File 'lib/deploy_pin/task.rb', line 120
def <=>(other)
sorting_key <=> other.sorting_key
end
|
#details ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/deploy_pin/task.rb', line 94
def details
{
identifier:,
group:,
title:
}
end
|
#done? ⇒ Boolean
57
58
59
60
61
62
|
# File 'lib/deploy_pin/task.rb', line 57
def done?
return if recurring
return unless record
record.completed_at.present?
end
|
#each_line(&block) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/deploy_pin/task.rb', line 86
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
102
103
104
105
|
# File 'lib/deploy_pin/task.rb', line 102
def eql?(other)
script == other.script && identifier != other.identifier
end
|
#increment_progress!(incrementor) ⇒ Object
51
52
53
54
55
|
# File 'lib/deploy_pin/task.rb', line 51
def increment_progress!(incrementor)
raise NotImplementedError, 'Recurring tasks do not support progress yet.' if recurring
record.increment!(:progress, incrementor)
end
|
#mark ⇒ Object
44
45
46
47
48
49
|
# File 'lib/deploy_pin/task.rb', line 44
def mark
return if recurring
record.update(completed_at: Time.current)
end
|
#parse ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/deploy_pin/task.rb', line 68
def parse
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[^#].*/
@script += line
@explicit_timeout = true if line =~ /Database.execute_with_timeout.*/
@parallel = true if line =~ /[Pp]arallel.*/
end
end
end
|
#prepare ⇒ Object
38
39
40
41
42
|
# File 'lib/deploy_pin/task.rb', line 38
def prepare
return if recurring
DeployPin::Record.create(uuid: identifier) unless record
end
|
#record ⇒ Object
34
35
36
|
# File 'lib/deploy_pin/task.rb', line 34
def record
DeployPin::Record.find_by(uuid: identifier)
end
|
#run ⇒ Object
29
30
31
32
|
# File 'lib/deploy_pin/task.rb', line 29
def run
eval(script)
end
|
#sorting_key ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/deploy_pin/task.rb', line 111
def sorting_key
if identifier.to_i.negative?
[group_index, unreachable_future + identifier]
else
[group_index, identifier]
end
end
|
#under_timeout? ⇒ Boolean
64
65
66
|
# File 'lib/deploy_pin/task.rb', line 64
def under_timeout?
!explicit_timeout? && !parallel?
end
|
#unreachable_future ⇒ Object
107
108
109
|
# File 'lib/deploy_pin/task.rb', line 107
def unreachable_future
1.year.from_now.to_date.strftime('%Y%m%d%H%M%S').to_i
end
|