deploy_pin 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -17
- data/lib/deploy_pin/database.rb +4 -20
- data/lib/deploy_pin/database_engine.rb +51 -0
- data/lib/deploy_pin/version.rb +1 -1
- data/lib/deploy_pin.rb +5 -4
- data/lib/generators/deploy_pin/task/templates/parallel_task.rb.erb +1 -0
- data/lib/generators/deploy_pin/task/templates/task.rb.erb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ebbfe96a88deeb425d7b53e1c3a99cda696fac889f80cb333bb912afe2ceba1
|
4
|
+
data.tar.gz: 2bda5afc250a357af2637cd950d3ed1f0362b0f32d2cf65782fe12081b88eca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2171f9ae37344e3fb589e99804362df12182fc1cae478b165d3d9f6d1c90b7ef86c5b34d2e099f22a5f168fbeca6e489de6526542f844edd029414fdb285f273
|
7
|
+
data.tar.gz: 734b7f41d25fc84abaff5e81e00c477ff382854e3175581113c967f758d5e31317d56710dbeeabf4bf198e6a27c11e96a5f678f62c4b97d8878261abbd1ded63
|
data/README.md
CHANGED
@@ -6,8 +6,6 @@
|
|
6
6
|
|
7
7
|
# DeployPin
|
8
8
|
|
9
|
-

|
10
|
-
|
11
9
|
Deploying applications often involves the need to execute a series of specific commands or tasks either before or after the deployment process. While you might typically turn to migrations for such operations, these tasks aren't always migration-related. Additionally, there are situations where you need to execute code before or after a migration without causing the main thread to block.
|
12
10
|
|
13
11
|
Introducing deploy_pins – your go-to solution for streamlined task management during the deployment process. This Ruby library allows you to seamlessly orchestrate tasks before, after, or independently of migrations, offering the flexibility you need to maintain a smooth and efficient deployment workflow. With deploy_pins, you can take control of your deployment tasks and ensure that your application operates flawlessly in any environment.
|
@@ -119,6 +117,7 @@ If you want to use a different value than the default, you need to specify it ex
|
|
119
117
|
# Some deploy_pin task
|
120
118
|
# 20190401135040:I
|
121
119
|
# task_title: Execute some query with timeout
|
120
|
+
# affected_areas: none
|
122
121
|
|
123
122
|
# === task code goes down here ===
|
124
123
|
DeployPin::Database::execute_with_timeout do
|
@@ -191,27 +190,29 @@ rails g deploy_pin:task some_task_title --parallel --recurring --identifier 5
|
|
191
190
|
## DeploymentStateTrack
|
192
191
|
In the initializer
|
193
192
|
```ruby
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
193
|
+
DeployPin.setup do
|
194
|
+
groups %w[I II III post rollback]
|
195
|
+
...
|
196
|
+
deployment_state_transition({
|
197
|
+
ongoing: %w[I III],
|
198
|
+
pending: "rollback", # enters to pending step before "rollback"
|
199
|
+
ttl: 20.second, # memoize the state to avoid Redis spam
|
200
|
+
redis_url: "redis://localhost:6379"
|
201
|
+
})
|
202
|
+
end
|
204
203
|
|
205
|
-
|
206
|
-
|
207
|
-
|
204
|
+
# enabled next methods
|
205
|
+
DeployPin.ongoing_deployment?
|
206
|
+
DeployPin.pending_deployment?
|
208
207
|
```
|
209
208
|
|
210
209
|
Around the deployment
|
211
210
|
```bash
|
212
|
-
|
213
|
-
|
211
|
+
bundle exec rake deploy_pin:run[I, II, III] - # enters to ongoing state before "I" and leaves it after "III" so all tasks in I, II, III have DeployPin.oingoing_deployment? == true
|
212
|
+
bundle exec rake deploy_pin:run[rollback] - # enters "pending state"
|
214
213
|
```
|
214
|
+
## Similar Gems
|
215
|
+
- https://github.com/theSteveMitchell/after_party
|
215
216
|
|
216
217
|
## Contributing
|
217
218
|
Contribution directions go here.
|
data/lib/deploy_pin/database.rb
CHANGED
@@ -2,13 +2,8 @@
|
|
2
2
|
|
3
3
|
module DeployPin
|
4
4
|
module Database
|
5
|
-
PG_TIMEOUT_STATEMENT = 'SET statement_timeout TO %s'
|
6
|
-
MYSQL_TIMEOUT_STATEMENT = 'SET max_execution_time = %s'
|
7
|
-
|
8
5
|
extend self
|
9
6
|
|
10
|
-
def dummy_method; end
|
11
|
-
|
12
7
|
# Run a block under a sql maximum timeout.
|
13
8
|
#
|
14
9
|
# A default timeout will be get from DeployPin.setup
|
@@ -21,6 +16,7 @@ module DeployPin
|
|
21
16
|
# # <app root>/deploy_pin/20190401135040_task.rb
|
22
17
|
# # 20190401135040:I
|
23
18
|
# # task_title: Execute some query with timeout
|
19
|
+
# # affected_areas: none
|
24
20
|
#
|
25
21
|
# # === task code goes down here ===
|
26
22
|
# DeployPin::Database::execute_with_timeout do
|
@@ -67,23 +63,11 @@ module DeployPin
|
|
67
63
|
|
68
64
|
def set_max_timeout(timeout)
|
69
65
|
timeout_in_milliseconds = timeout.to_f.in_milliseconds.ceil # Make sure is always at least 1. 0 turns this off
|
70
|
-
|
71
|
-
timeout_statement =
|
72
|
-
if postgresql?
|
73
|
-
PG_TIMEOUT_STATEMENT
|
74
|
-
elsif mysql?
|
75
|
-
MYSQL_TIMEOUT_STATEMENT
|
76
|
-
end
|
77
|
-
|
78
|
-
connection.execute timeout_statement % connection.quote(timeout_in_milliseconds)
|
79
|
-
end
|
80
|
-
|
81
|
-
def postgresql?
|
82
|
-
connection.adapter_name =~ /postg/i
|
66
|
+
connection.execute db_engine::TIMEOUT_STATEMENT % connection.quote(timeout_in_milliseconds)
|
83
67
|
end
|
84
68
|
|
85
|
-
def
|
86
|
-
connection.
|
69
|
+
def db_engine
|
70
|
+
@db_engine ||= DeployPin::DatabaseEngine.new(connection).detect
|
87
71
|
end
|
88
72
|
|
89
73
|
def connection
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeployPin
|
4
|
+
# This class is used to detect used database engine and managing specific
|
5
|
+
# differences between them.
|
6
|
+
class DatabaseEngine
|
7
|
+
module PostgreSQL
|
8
|
+
TIMEOUT_STATEMENT = 'SET statement_timeout TO %s'
|
9
|
+
end
|
10
|
+
|
11
|
+
module MySQL
|
12
|
+
TIMEOUT_STATEMENT = 'SET max_execution_time = %s'
|
13
|
+
end
|
14
|
+
|
15
|
+
module MariaDB
|
16
|
+
TIMEOUT_STATEMENT = 'SET SESSION max_statement_time = %s'
|
17
|
+
end
|
18
|
+
|
19
|
+
DB_ENGINES_MAPPING = {
|
20
|
+
mariadb: MariaDB,
|
21
|
+
mysql: MySQL,
|
22
|
+
pg: PostgreSQL
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
def initialize(connection)
|
26
|
+
@connection = connection
|
27
|
+
end
|
28
|
+
|
29
|
+
def detect
|
30
|
+
db_engine_symbol =
|
31
|
+
case connection.adapter_name
|
32
|
+
when /postg/i then :pg
|
33
|
+
when /mysql/i, /trilogy/i then detect_mysql_based_engine
|
34
|
+
end
|
35
|
+
|
36
|
+
DB_ENGINES_MAPPING[db_engine_symbol]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :connection
|
42
|
+
|
43
|
+
def detect_mysql_based_engine
|
44
|
+
mariadb? ? :mariadb : :mysql
|
45
|
+
end
|
46
|
+
|
47
|
+
def mariadb?
|
48
|
+
connection.select_value('SELECT VERSION()') =~ /MariaDB/i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/deploy_pin/version.rb
CHANGED
data/lib/deploy_pin.rb
CHANGED
@@ -8,20 +8,21 @@ require 'deploy_pin/task'
|
|
8
8
|
require 'deploy_pin/task_criteria'
|
9
9
|
require 'deploy_pin/engine'
|
10
10
|
require 'deploy_pin/database'
|
11
|
+
require 'deploy_pin/database_engine'
|
11
12
|
require 'parallel'
|
12
13
|
require 'ruby-progressbar'
|
13
14
|
require 'colorize'
|
14
15
|
|
15
16
|
module DeployPin
|
16
17
|
OPTIONS = %i[
|
17
|
-
|
18
|
+
deployment_state_transition
|
18
19
|
fallback_group
|
19
20
|
groups
|
20
|
-
statement_timeout
|
21
|
-
run_formatter
|
22
21
|
list_formatter
|
22
|
+
run_formatter
|
23
|
+
statement_timeout
|
23
24
|
task_wrapper
|
24
|
-
|
25
|
+
tasks_path
|
25
26
|
].freeze
|
26
27
|
|
27
28
|
DEFAULTS = {
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# <%= @identifier %>:<%= @group %><%= @recurring ? ":recurring" : "" %>
|
4
4
|
# task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
|
5
|
+
# affected_areas: none
|
5
6
|
|
6
7
|
# === parallel task code goes down here ===
|
7
8
|
10.times { DeployPin::Record.create(uuid: "hello") }
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# <%= @identifier %>:<%= @group %><%= @recurring ? ":recurring" : "" %>
|
4
4
|
# task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
|
5
|
+
# affected_areas: none
|
5
6
|
|
6
7
|
# === task code goes down here ===
|
7
8
|
progressbar = ProgressBar.create(title: "Doing stuff", total: 20, format: '%t |%E | %B | %a')
|
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.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Sych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- lib/deploy_pin.rb
|
236
236
|
- lib/deploy_pin/collector.rb
|
237
237
|
- lib/deploy_pin/database.rb
|
238
|
+
- lib/deploy_pin/database_engine.rb
|
238
239
|
- lib/deploy_pin/deployment_state.rb
|
239
240
|
- lib/deploy_pin/engine.rb
|
240
241
|
- lib/deploy_pin/parallel_wrapper.rb
|
@@ -271,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
272
|
- !ruby/object:Gem::Version
|
272
273
|
version: '0'
|
273
274
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
275
|
+
rubygems_version: 3.5.16
|
275
276
|
signing_key:
|
276
277
|
specification_version: 4
|
277
278
|
summary: pin some task around deployment
|