deploy_pin 1.3.6 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -2
- data/lib/deploy_pin/collector.rb +18 -8
- data/lib/deploy_pin/runner.rb +3 -18
- data/lib/deploy_pin/task.rb +10 -6
- data/lib/deploy_pin/version.rb +1 -1
- data/lib/deploy_pin.rb +2 -0
- data/lib/generators/deploy_pin/install/templates/deploy_pin.rb +23 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3d6aa336c010d58ff4462cc64038351fa67432faf2f4dd3e094b12d3c912c9e
|
4
|
+
data.tar.gz: a9e8d29ac5e8db0c207f2e40a59f6d77013c98efbf7e9cb38c5b1e1b6840f577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf2efc8fd1cc48f8e1bf5568bb11544d6a20510e7bbfa2ae81f63f831da6776945b6dc22e5d9befa444c77d042b3d6a9a87bb9b40f246c4a54e9801fd960069a
|
7
|
+
data.tar.gz: 1527b98cccfec97dad84286cea3063c9a76a051f9286a8be01181bb1bd1c6032e94693b57ed1f3cfea7b1286a2849d5fa2e36a0d8e7a1fe90f41dba946212c63
|
data/README.md
CHANGED
@@ -110,7 +110,7 @@ A default value must be defined in the deploy_pin initializer. Ex.:
|
|
110
110
|
# config/initializers/deploy_pin.rb
|
111
111
|
DeployPin.setup do
|
112
112
|
statement_timeout 0.2.second # 200 ms
|
113
|
-
end
|
113
|
+
end
|
114
114
|
```
|
115
115
|
|
116
116
|
In order to not use the default value, it's required to use explicitly in the task, like:
|
@@ -127,7 +127,7 @@ end
|
|
127
127
|
|
128
128
|
To know more about the params, please check the documentation [here](lib/deploy_pin/database.rb).
|
129
129
|
|
130
|
-
|
130
|
+
## Parallel
|
131
131
|
To run parallel tasks using timeout, it's required to use the parallel wrapper, which mimics parallel interface,
|
132
132
|
but adding the timeout option.
|
133
133
|
|
@@ -142,6 +142,52 @@ end
|
|
142
142
|
|
143
143
|
Check the documentation [here](lib/deploy_pin/parallel_wrapper.rb).
|
144
144
|
|
145
|
+
## Formatting
|
146
|
+
`run_formatter` is used to format the output of a `run` task
|
147
|
+
`list_formatter` is used to format the output of a `list` task
|
148
|
+
|
149
|
+
A default value must be defined in the deploy_pin initializer. Ex.:
|
150
|
+
```ruby
|
151
|
+
# config/initializers/deploy_pin.rb
|
152
|
+
DeployPin.setup do
|
153
|
+
run_formatter(
|
154
|
+
lambda do |index, task_count, task, executable, start, duration = nil|
|
155
|
+
end_of_msg = if executable
|
156
|
+
start ? '(Started)' : "(Done in #{duration})\n\n"
|
157
|
+
else
|
158
|
+
"(Skipped)\n\n"
|
159
|
+
end
|
160
|
+
|
161
|
+
puts("[#{index + 1}/#{task_count}] Task #{task.title} #{task.uuid}##{task.group} #{end_of_msg}".blue.bold)
|
162
|
+
end
|
163
|
+
)
|
164
|
+
list_formatter(
|
165
|
+
lambda do |index, task|
|
166
|
+
puts("======= Task ##{index} ========".blue.bold)
|
167
|
+
|
168
|
+
# print details
|
169
|
+
task.details.each do |key, value|
|
170
|
+
puts("#{key}:\t\t#{value}")
|
171
|
+
end
|
172
|
+
|
173
|
+
puts("\n<<<\n#{task.script.strip.green}\n>>>\n\n")
|
174
|
+
end
|
175
|
+
)
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
In order to not use the default value, it's required to use explicitly in the task, like:
|
180
|
+
```ruby
|
181
|
+
# Some deploy_pin task
|
182
|
+
# 20190401135040:I
|
183
|
+
# task_title: Execute some query with timeout
|
184
|
+
|
185
|
+
# === task code goes down here ===
|
186
|
+
DeployPin::Database::execute_with_timeout do
|
187
|
+
ActiveRecord::Base.connection.execute("select * from shipments;")
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
145
191
|
## Contributing
|
146
192
|
Contribution directions go here.
|
147
193
|
|
data/lib/deploy_pin/collector.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# executes tasks
|
4
4
|
module DeployPin
|
5
5
|
class Collector
|
6
|
-
attr_reader :identifiers
|
6
|
+
attr_reader :identifiers, :formatter
|
7
7
|
|
8
8
|
def initialize(identifiers:)
|
9
9
|
@identifiers = identifiers
|
@@ -16,13 +16,15 @@ module DeployPin
|
|
16
16
|
# run only uniq tasks
|
17
17
|
executable = _tasks[0..index].none? { |_task| task.eql?(_task) }
|
18
18
|
|
19
|
-
|
19
|
+
DeployPin.run_formatter.call(index, _tasks.count, task, executable, true)
|
20
20
|
|
21
21
|
# run if executable
|
22
22
|
if executable
|
23
|
-
|
24
|
-
task.run
|
23
|
+
duration = execution_duration do
|
24
|
+
run_with_timeout(task) { task.run }
|
25
25
|
end
|
26
|
+
|
27
|
+
DeployPin.run_formatter.call(index, _tasks.count, task, executable, false, duration)
|
26
28
|
end
|
27
29
|
|
28
30
|
# mark each task as done
|
@@ -33,11 +35,11 @@ module DeployPin
|
|
33
35
|
def list
|
34
36
|
_tasks = tasks
|
35
37
|
_tasks.each_with_index do |task, index|
|
36
|
-
|
38
|
+
DeployPin.list_formatter.call(index, task)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
42
|
+
def executable
|
41
43
|
# cache tasks
|
42
44
|
_tasks = tasks
|
43
45
|
_tasks.map.with_index do |task, index|
|
@@ -71,10 +73,18 @@ module DeployPin
|
|
71
73
|
end
|
72
74
|
|
73
75
|
# :reek:UtilityFunction and :reek:ControlParameter
|
74
|
-
def run_with_timeout(
|
75
|
-
return yield unless under_timeout
|
76
|
+
def run_with_timeout(task, &block)
|
77
|
+
return yield unless task.under_timeout?
|
76
78
|
|
77
79
|
DeployPin::Database.execute_with_timeout(DeployPin.statement_timeout, **{}, &block)
|
78
80
|
end
|
81
|
+
|
82
|
+
def execution_duration
|
83
|
+
start_time = Time.now
|
84
|
+
|
85
|
+
yield
|
86
|
+
|
87
|
+
Time.now - start_time
|
88
|
+
end
|
79
89
|
end
|
80
90
|
end
|
data/lib/deploy_pin/runner.rb
CHANGED
@@ -4,32 +4,17 @@
|
|
4
4
|
module DeployPin
|
5
5
|
module Runner
|
6
6
|
def self.run(identifiers:)
|
7
|
-
DeployPin::Collector.new(identifiers: identifiers).run
|
8
|
-
self.print("[#{index + 1}/#{count}] Task #{task.title} #{task.uuid}##{task.group} (#{executable ? 'run' : 'skip'})")
|
9
|
-
end
|
7
|
+
DeployPin::Collector.new(identifiers: identifiers).run
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.list(identifiers:)
|
13
|
-
DeployPin::Collector.new(identifiers: identifiers).list
|
14
|
-
self.print("======= Task ##{index} ========".white)
|
15
|
-
|
16
|
-
# print details
|
17
|
-
task.details.each do |key, value|
|
18
|
-
self.print("#{key}:\t\t#{value}")
|
19
|
-
end
|
20
|
-
|
21
|
-
self.print('')
|
22
|
-
self.print('<<<')
|
23
|
-
self.print task.script.strip.green
|
24
|
-
self.print('>>>')
|
25
|
-
self.print('')
|
26
|
-
end
|
11
|
+
DeployPin::Collector.new(identifiers: identifiers).list
|
27
12
|
end
|
28
13
|
|
29
14
|
def self.summary(identifiers:)
|
30
15
|
# print summary
|
31
16
|
self.print('======= Summary ========')
|
32
|
-
self.print("
|
17
|
+
self.print("Tasks number: #{DeployPin::Collector.new(identifiers: identifiers).tasks_count}")
|
33
18
|
end
|
34
19
|
|
35
20
|
def self.print(msg)
|
data/lib/deploy_pin/task.rb
CHANGED
@@ -37,12 +37,8 @@ module DeployPin
|
|
37
37
|
DeployPin::Record.where(uuid: uuid).exists?
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def parallel?
|
45
|
-
@parallel
|
40
|
+
def under_timeout?
|
41
|
+
!explicit_timeout? && !parallel?
|
46
42
|
end
|
47
43
|
|
48
44
|
def parse_file
|
@@ -85,5 +81,13 @@ module DeployPin
|
|
85
81
|
def group_index
|
86
82
|
DeployPin.groups.index(group)
|
87
83
|
end
|
84
|
+
|
85
|
+
def explicit_timeout?
|
86
|
+
@explicit_timeout
|
87
|
+
end
|
88
|
+
|
89
|
+
def parallel?
|
90
|
+
@parallel
|
91
|
+
end
|
88
92
|
end
|
89
93
|
end
|
data/lib/deploy_pin/version.rb
CHANGED
data/lib/deploy_pin.rb
CHANGED
@@ -4,6 +4,28 @@ DeployPin.setup do
|
|
4
4
|
tasks_path 'lib/deploy_pin'
|
5
5
|
groups %w[I II III]
|
6
6
|
fallback_group 'II'
|
7
|
-
|
8
7
|
statement_timeout 10.minutes
|
8
|
+
run_formatter(
|
9
|
+
lambda do |index, task_count, task, executable, start, duration = nil|
|
10
|
+
end_of_msg = if executable
|
11
|
+
start ? '(Started)' : "(Done in #{duration})\n\n"
|
12
|
+
else
|
13
|
+
"(Skipped)\n\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
puts("[#{index + 1}/#{task_count}] Task #{task.title} #{task.uuid}##{task.group} #{end_of_msg}".blue.bold)
|
17
|
+
end
|
18
|
+
)
|
19
|
+
list_formatter(
|
20
|
+
lambda do |index, task|
|
21
|
+
puts("======= Task ##{index} ========".blue.bold)
|
22
|
+
|
23
|
+
# print details
|
24
|
+
task.details.each do |key, value|
|
25
|
+
puts("#{key}:\t\t#{value}")
|
26
|
+
end
|
27
|
+
|
28
|
+
puts("\n<<<\n#{task.script.strip.green}\n>>>\n\n")
|
29
|
+
end
|
30
|
+
)
|
9
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deploy_pin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Sych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|