deploy_pin 1.3.1 → 1.3.3

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: f3006ccc3913b4cc7ee0b5d68b316ffb70ecef2bbfeae27c7efec65422246cdb
4
- data.tar.gz: d055a8554b590bc039915d3a2866f23aa8541db9ffe8c2c933294f54c2013785
3
+ metadata.gz: dd55cf51dd48871190b26b687e0e43ca56a460b5f38b26b65f48549c5e0e4c01
4
+ data.tar.gz: 814a4adaaaa6c967e715ea38ac264b76e5f2292ed79a9df5ecbaec3b8e804c99
5
5
  SHA512:
6
- metadata.gz: 70d4054142995c62609666711a87d4d4e42783bf4631e61f3a43e3407a9cd68654de65b0925655ca416fb65e41bccd3a2246125e446f5f4d8a9cb48f70e7ffd4
7
- data.tar.gz: 654cbb997e23bf9a2cc9d8579e71646f68fd669dfd92235da2a1d15b8b3d9775b01db714ce99e79e23e6389282a907c2f9ae5b573c348bd4b0d3f43105989903
6
+ metadata.gz: ac2cc4f44f70d66807b46369c2b9a942ef07eaaab858ed988c6e9dfebd4e02c0f0495fa9e5989f7204300a55150d5c8e3cbbaa10e33c9a7d6a77d16a18ce4c00
7
+ data.tar.gz: 37f7a702ae8d696c002a3b4af04b77e590ed20f9c81920d39ede0ec0d942b2c8ed82c7a439a08bb7a94d6d3e9fb5f531405dc796ec819248417750980afde7d4
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/deploy_pin.svg)](https://badge.fury.io/rb/deploy_pin)
2
2
  ![](https://ruby-gem-downloads-badge.herokuapp.com/deploy_pin)
3
3
  ![example workflow](https://github.com/skcc321/deploy_pin/actions/workflows/verify.yml/badge.svg)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/maintainability)](https://codeclimate.com/github/skcc321/deploy_pin/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/test_coverage)](https://codeclimate.com/github/skcc321/deploy_pin/test_coverage)
6
4
 
7
5
  # DeployPin
8
6
 
@@ -21,9 +19,14 @@ deploy_pins is exactly what you need.
21
19
 
22
20
  To generate new task template file
23
21
  ```bash
24
- rails g deploy_pin:task
22
+ rails g deploy_pin:task some_task_title
25
23
  # or
26
- rails g deploy_pin:task --parallel
24
+ rails g deploy_pin:task some_task_title --parallel
25
+ ```
26
+
27
+ Also, you can specify author
28
+ ```bash
29
+ rails g deploy_pin:task some_task_title -a author_name
27
30
  ```
28
31
 
29
32
  To list all pending tasks
@@ -40,11 +43,10 @@ rake deploy_pin:run
40
43
 
41
44
  Please define allowed groups in `config/initializers/deploy_pin.rb`
42
45
  if you want to group tasks around "allowed_group"
43
-
44
46
  ```bash
45
- rails g deploy_pin:task allowed_group
47
+ rails g deploy_pin:task task_title -g allowed_group
46
48
  # or
47
- rails g deploy_pin:task allowed_group --parallel
49
+ rails g deploy_pin:task task_title -g allowed_group --parallel
48
50
  ```
49
51
 
50
52
  To list all pending tasks
@@ -101,6 +103,45 @@ and run migration
101
103
  rake db:migrate
102
104
  ```
103
105
 
106
+ ## Database Timeout
107
+ By default, deploy_pin will run all the non-parallel tasks under a database statement timeout.
108
+ A default value must be defined in the deploy_pin initializer. Ex.:
109
+ ```ruby
110
+ # config/initializers/deploy_pin.rb
111
+ DeployPin.setup do
112
+ statement_timeout 0.2.second # 200 ms
113
+ end
114
+ ```
115
+
116
+ In order to not use the default value, it's required to use explicitly in the task, like:
117
+ ```ruby
118
+ # Some deploy_pin task
119
+ # 20190401135040:I
120
+ # task_title: Execute some query with timeout
121
+
122
+ # === task code goes down here ===
123
+ DeployPin::Database::execute_with_timeout do
124
+ ActiveRecord::Base.connection.execute("select * from shipments;")
125
+ end
126
+ ```
127
+
128
+ To know more about the params, please check the documentation [here](lib/deploy_pin/database.rb).
129
+
130
+ ### Parallel
131
+ To run parallel tasks using timeout, it's required to use the parallel wrapper, which mimics parallel interface,
132
+ but adding the timeout option.
133
+
134
+ In a deploy_pin task, instead of using `Parallel.each(1..2, in_processes: 2)`, use:
135
+ ```ruby
136
+ parallel_each(1..2, in_processes: 2, timeout: 0.3.seconds) do |i|
137
+ # ActiveRecord::Base.connection_pool.with_connection it's already include in the parallel wrapper.
138
+ puts "Item: #{i}, Worker: #{Parallel.worker_number}"
139
+ ActiveRecord::Base.connection.execute("<some db query>")
140
+ end
141
+ ```
142
+
143
+ Check the documentation [here](lib/deploy_pin/parallel_wrapper.rb).
144
+
104
145
  ## Contributing
105
146
  Contribution directions go here.
106
147
 
@@ -50,6 +50,7 @@ module DeployPin
50
50
  end
51
51
 
52
52
  private
53
+
53
54
  # :reek:UtilityFunction
54
55
  def files
55
56
  Dir["#{DeployPin.tasks_path}/*.rb"]
@@ -7,6 +7,8 @@ module DeployPin
7
7
 
8
8
  extend self
9
9
 
10
+ def dummy_method; end
11
+
10
12
  # Run a block under a sql maximum timeout.
11
13
  #
12
14
  # A default timeout will be get from DeployPin.setup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeployPin
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.3'
5
5
  end
@@ -2,7 +2,7 @@ Description:
2
2
  Creates tasks for execution on deployment
3
3
 
4
4
  Example:
5
- rails generate deploy_pin:task
5
+ rails generate deploy_pin:task some_name_of_task -a author -g I
6
6
 
7
7
  This will create:
8
- lib/deploy_pin/task.rb
8
+ lib/deploy_pin/{task_id}_some_name_of_task.rb
@@ -2,22 +2,23 @@
2
2
 
3
3
  class DeployPin::TaskGenerator < Rails::Generators::Base
4
4
  class_option :parallel, type: :boolean
5
- argument :group, default: DeployPin.fallback_group
5
+ argument :title, required: true
6
+ class_option :group, aliases: '-g', default: DeployPin.fallback_group
7
+ class_option :author, aliases: '-a'
6
8
 
7
9
  source_root File.expand_path('templates', __dir__)
8
10
 
9
11
  desc 'This generator creates deploy_pin task at lib/deploy_pin/'
10
12
  def create_task_file
11
- raise "Not allowed 'group' argument! possible values are #{DeployPin.groups}" \
12
- unless DeployPin.groups.include?(group)
13
-
14
13
  template_file = if options[:parallel]
15
14
  'parallel_task.rb.erb'
16
15
  else
17
16
  'task.rb.erb'
18
17
  end
19
18
 
19
+ @author = options[:author] || ENV['USER']
20
+ @group = options[:group]
20
21
  @uuid = Time.now.strftime('%Y%m%d%H%M%S')
21
- template template_file, "#{DeployPin.tasks_path}/#{@uuid}_task.rb"
22
+ template template_file, "#{DeployPin.tasks_path}/#{@uuid}_#{title}.rb"
22
23
  end
23
24
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # <%= @uuid %>:<%= group %>
4
- # task_title: super duper task
3
+ # <%= @uuid %>:<%= @group %>
4
+ # task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
5
5
 
6
6
  # === parallel task code goes down here ===
7
7
  10.times { DeployPin::Record.create(uuid: "hello") }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # <%= @uuid %>:<%= group %>
4
- # task_title: super duper task
3
+ # <%= @uuid %>:<%= @group %>
4
+ # task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
5
5
 
6
6
  # === task code goes down here ===
7
7
  progressbar = ProgressBar.create(title: "Doing stuff", total: 20, format: '%t |%E | %B | %a')
@@ -12,4 +12,4 @@ progressbar = ProgressBar.create(title: "Doing stuff", total: 20, format: '%t |%
12
12
  # ActiveRecord::Base.connection.execute("select * from shipments;")
13
13
  # or
14
14
  # Shipment.all
15
- # end
15
+ # 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.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -150,6 +150,34 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov-review
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: pin some task around deployment to execute them during deployment circle
154
182
  email:
155
183
  - skcc321@gmail.com