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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa5407ab78ca3ddbdb272cdda4b08174f7f17e031d7e51eeecdcef087e1cf636
4
- data.tar.gz: 7d7d77724bbb23a0f96223f84c451c948dd85c751b1d0fff3dd05af769491b75
3
+ metadata.gz: 4d5801fe8a830296f5f65c20239b11872f2e0c80cde1934a8ab953946b544ed8
4
+ data.tar.gz: 162751453a48bd062984e378a1bfb33825d76bf2b700e6a38324fd60c5f714e8
5
5
  SHA512:
6
- metadata.gz: b363c3124fde01c582c534b90df9f2624fee9f37bb439d8a5e948672456aedb5c3162b68fb9075f910035296611228166e5306b89e6b2d9898ed2d121f397d3a
7
- data.tar.gz: ed934dc9afcc4e530e6079f040bbd551a72e4ab9fccb5961d573d9bd2844cad65e0f919b3ba7bc340e5c8c935d126b4c6d0ceae57b953af0fb97e9efc3f9bd97
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
- ### Parallel
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
 
@@ -3,7 +3,9 @@
3
3
  # executes tasks
4
4
  module DeployPin
5
5
  class Collector
6
- attr_reader :identifiers
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
- yield(index, _tasks.count, task, executable)
21
+ DeployPin.run_formatter.call(index, _tasks.count, task, executable, true)
20
22
 
21
23
  # run if executable
22
24
  if executable
23
- run_with_timeout(!task.explicit_timeout? && !task.parallel?) do
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
- yield(index, _tasks.count, task)
40
+ DeployPin.list_formatter.call(index, task)
37
41
  end
38
42
  end
39
43
 
40
- def exacutable
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(under_timeout, &block)
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
@@ -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 do |index, count, task, executable|
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 do |index, _count, task|
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("tasks number: #{DeployPin::Collector.new(identifiers: identifiers).tasks_count}")
17
+ self.print("Tasks number: #{DeployPin::Collector.new(identifiers: identifiers).tasks_count}")
33
18
  end
34
19
 
35
20
  def self.print(msg)
@@ -37,12 +37,8 @@ module DeployPin
37
37
  DeployPin::Record.where(uuid: uuid).exists?
38
38
  end
39
39
 
40
- def explicit_timeout?
41
- @explicit_timeout
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeployPin
4
- VERSION = '1.3.5'
4
+ VERSION = '1.3.7'
5
5
  end
data/lib/deploy_pin.rb CHANGED
@@ -17,6 +17,8 @@ module DeployPin
17
17
  fallback_group
18
18
  groups
19
19
  statement_timeout
20
+ run_formatter
21
+ list_formatter
20
22
  ].freeze
21
23
 
22
24
  OPTIONS.each do |option|
@@ -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.5
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-02-20 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize