deploy_pin 1.3.5 → 1.3.7
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 +20 -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: 4d5801fe8a830296f5f65c20239b11872f2e0c80cde1934a8ab953946b544ed8
|
4
|
+
data.tar.gz: 162751453a48bd062984e378a1bfb33825d76bf2b700e6a38324fd60c5f714e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0189c0b921ed86800c1d4c7a1ce7b89f6af1a06ee8f2ced34de0797a7318fd7a508335bbd28980d01e07fce6c467c5117c781ee5958b23c0e8e1b76b33640591'
|
7
|
+
data.tar.gz: 1e25f0d9854201ec343414547f3dc720a932cf92053c245c878095480622ac36d8fdb42ed77d6a4bce10348960595742dcc189ba2f8500eeec94073e07f773bf
|
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, time = nil|
|
155
|
+
end_of_msg = if executable
|
156
|
+
start ? '(Started)' : "(Done in #{time})\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,9 @@
|
|
3
3
|
# executes tasks
|
4
4
|
module DeployPin
|
5
5
|
class Collector
|
6
|
-
|
6
|
+
include ActionView::Helpers::DateHelper
|
7
|
+
|
8
|
+
attr_reader :identifiers, :formatter
|
7
9
|
|
8
10
|
def initialize(identifiers:)
|
9
11
|
@identifiers = identifiers
|
@@ -16,13 +18,15 @@ module DeployPin
|
|
16
18
|
# run only uniq tasks
|
17
19
|
executable = _tasks[0..index].none? { |_task| task.eql?(_task) }
|
18
20
|
|
19
|
-
|
21
|
+
DeployPin.run_formatter.call(index, _tasks.count, task, executable, true)
|
20
22
|
|
21
23
|
# run if executable
|
22
24
|
if executable
|
23
|
-
|
24
|
-
task.run
|
25
|
+
time = execution_time do
|
26
|
+
run_with_timeout(task) { task.run }
|
25
27
|
end
|
28
|
+
|
29
|
+
DeployPin.run_formatter.call(index, _tasks.count, task, executable, false, time)
|
26
30
|
end
|
27
31
|
|
28
32
|
# mark each task as done
|
@@ -33,11 +37,11 @@ module DeployPin
|
|
33
37
|
def list
|
34
38
|
_tasks = tasks
|
35
39
|
_tasks.each_with_index do |task, index|
|
36
|
-
|
40
|
+
DeployPin.list_formatter.call(index, task)
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
44
|
+
def executable
|
41
45
|
# cache tasks
|
42
46
|
_tasks = tasks
|
43
47
|
_tasks.map.with_index do |task, index|
|
@@ -71,10 +75,18 @@ module DeployPin
|
|
71
75
|
end
|
72
76
|
|
73
77
|
# :reek:UtilityFunction and :reek:ControlParameter
|
74
|
-
def run_with_timeout(
|
75
|
-
return yield unless under_timeout
|
78
|
+
def run_with_timeout(task, &block)
|
79
|
+
return yield unless task.under_timeout?
|
76
80
|
|
77
81
|
DeployPin::Database.execute_with_timeout(DeployPin.statement_timeout, **{}, &block)
|
78
82
|
end
|
83
|
+
|
84
|
+
def execution_time
|
85
|
+
start_time = Time.now
|
86
|
+
|
87
|
+
yield
|
88
|
+
|
89
|
+
time_ago_in_words(start_time)
|
90
|
+
end
|
79
91
|
end
|
80
92
|
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, time = nil|
|
10
|
+
end_of_msg = if executable
|
11
|
+
start ? '(Started)' : "(Done in #{time})\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.7
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|