deploy_pin 1.5.1 → 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: c21646b048b09408bf131ab463208e76dd54b18596dcdfce4c16fae3fa1669f1
4
- data.tar.gz: 5ac45e42ba5a3af95dadbf44031e683997f8fe42a8e422f1d7114f5007437e8e
3
+ metadata.gz: 7ebbfe96a88deeb425d7b53e1c3a99cda696fac889f80cb333bb912afe2ceba1
4
+ data.tar.gz: 2bda5afc250a357af2637cd950d3ed1f0362b0f32d2cf65782fe12081b88eca0
5
5
  SHA512:
6
- metadata.gz: 6137f6270259681a0a74188e1a0145894d25eb77bde43d8ed47b9dea38c1ab7733ca618b44ac04d15e6ebbaf3f565200cb09af3ee91e8f9b2fca756ee9c5c250
7
- data.tar.gz: 8551c4fadd20f97cd19584566408a115d42a9402b45b46fba4c4fdf6e94b3f1b9b074136287b814ca3ff1603bfe77b5fa51bbc9814fcdf1ef59f421dd6052025
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.
@@ -192,27 +190,29 @@ rails g deploy_pin:task some_task_title --parallel --recurring --identifier 5
192
190
  ## DeploymentStateTrack
193
191
  In the initializer
194
192
  ```ruby
195
- DeployPin.setup do
196
- groups %w[I II III post rollback]
197
- ...
198
- deployment_state_transition({
199
- ongoing: %w[I III],
200
- pending: "rollback", # enters to pending step before "rollback"
201
- ttl: 20.second, # memoize the state to avoid Redis spam
202
- redis_url: "redis://localhost:6379"
203
- })
204
- 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
205
203
 
206
- # enabled next methods
207
- DeployPin.ongoing_deployment?
208
- DeployPin.pending_deployment?
204
+ # enabled next methods
205
+ DeployPin.ongoing_deployment?
206
+ DeployPin.pending_deployment?
209
207
  ```
210
208
 
211
209
  Around the deployment
212
210
  ```bash
213
- 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
214
- 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"
215
213
  ```
214
+ ## Similar Gems
215
+ - https://github.com/theSteveMitchell/after_party
216
216
 
217
217
  ## Contributing
218
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
@@ -68,23 +63,11 @@ module DeployPin
68
63
 
69
64
  def set_max_timeout(timeout)
70
65
  timeout_in_milliseconds = timeout.to_f.in_milliseconds.ceil # Make sure is always at least 1. 0 turns this off
71
-
72
- timeout_statement =
73
- if postgresql?
74
- PG_TIMEOUT_STATEMENT
75
- elsif mysql?
76
- MYSQL_TIMEOUT_STATEMENT
77
- end
78
-
79
- connection.execute timeout_statement % connection.quote(timeout_in_milliseconds)
80
- end
81
-
82
- def postgresql?
83
- connection.adapter_name =~ /postg/i
66
+ connection.execute db_engine::TIMEOUT_STATEMENT % connection.quote(timeout_in_milliseconds)
84
67
  end
85
68
 
86
- def mysql?
87
- connection.adapter_name =~ /mysql/i
69
+ def db_engine
70
+ @db_engine ||= DeployPin::DatabaseEngine.new(connection).detect
88
71
  end
89
72
 
90
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.1'
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 = {
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.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: 2024-09-19 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.5.11
275
+ rubygems_version: 3.5.16
275
276
  signing_key:
276
277
  specification_version: 4
277
278
  summary: pin some task around deployment