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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4dfa8e844cfa02e0324e4af067d6ac5a8e3d8b7829a90970bf7db6cb60cdb47
4
- data.tar.gz: caf02bfb5aaa6e6edd82f83bacef7113f0c62de799cbfebe45b94d88d71553e1
3
+ metadata.gz: 7ebbfe96a88deeb425d7b53e1c3a99cda696fac889f80cb333bb912afe2ceba1
4
+ data.tar.gz: 2bda5afc250a357af2637cd950d3ed1f0362b0f32d2cf65782fe12081b88eca0
5
5
  SHA512:
6
- metadata.gz: '0909b4f5366aeeb71e51cacf70d72d08a18486eab638d428950a53e6735155afb6af6bcab7c48095511372a18b9deac024a25adb291fab2206c79e63a61a9175'
7
- data.tar.gz: ce86dd3f2c2f7d6c3ec2957e1c1cb3eab4618aa88979b61418d6ca03fa2e9c5c59651aa5db630df166c1da05e9c126829e0b3823dd18ce3a0c8b733092fdbf33
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
- ![DeployPin](http://hereisfree.com/content1//pic/zip/2009109935062477801.jpg)
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
- DeployPin.setup do
195
- groups %w[I II III post rollback]
196
- ...
197
- deployment_state_transition({
198
- ongoing: %w[I III],
199
- pending: "rollback", # enters to pending step before "rollback"
200
- ttl: 20.second, # memoize the state to avoid Redis spam
201
- redis_url: "redis://localhost:6379"
202
- })
203
- end
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
- # enabled next methods
206
- DeployPin.ongoing_deployment?
207
- DeployPin.pending_deployment?
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
- 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
213
- bundle exec rake deploy_pin:run[rollback] - # enters "pending state"
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.
@@ -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 mysql?
86
- connection.adapter_name =~ /mysql/i
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeployPin
4
- VERSION = '1.5.0'
4
+ VERSION = '1.6.0'
5
5
  end
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
- tasks_path
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
- deployment_state_transition
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.5.0
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: 2023-10-30 00:00:00.000000000 Z
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.4.10
275
+ rubygems_version: 3.5.16
275
276
  signing_key:
276
277
  specification_version: 4
277
278
  summary: pin some task around deployment