deploy_pin 1.2.3 → 1.3.2

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: 7675586dc8be3862feb563927693c5aea136bb26983e261d97e995f111294c99
4
- data.tar.gz: de5d52bec5a3cff487667ae8a8bdb8af75b51f754507c0fb57e2f3db2cc9fd36
3
+ metadata.gz: 0133c82dd0826300585629d58af3f3e10a58b481e7c65a589a834fd0d7d79bdd
4
+ data.tar.gz: 220af2e000347c6835673f664f3413d3775cba0d3f1ccb9778cd324fcce1f08a
5
5
  SHA512:
6
- metadata.gz: 06bf8fbe7319167b1b9b5f32af3a2116debf608c3d4c8d10835436d475ada3d21f2259d32bb0adb6832c973b3b1c279753a4e4a9abf0748ee11a63265575cc53
7
- data.tar.gz: ea0f4017dd721cddfcfd75b36f81332903bdc615089631569acdfa98e0e263e60559273e32f4bedc2bb1449846e4d7f25d41a390b24d548024336a5f02803e33
6
+ metadata.gz: 602e2f80e418e91e0d0045b5f5635c001d221217566581df4eea11b499dcd974b188b5de5adc7b37452c156f2c00d35b8238e4bc80a6d50ba2c962d48df7952f
7
+ data.tar.gz: 202f198bb6197464495d7b418a568022b2869bf8800c959ffc09310db7a7335c16bd902652cda7b5ee2a734335bb88e35722f278f84005683935b29e6a0c9651
data/README.md CHANGED
@@ -1,6 +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
- [![Build Status](https://travis-ci.org/skcc321/deploy_pin.svg?branch=master)](https://travis-ci.org/skcc321/deploy_pin)
3
+ ![example workflow](https://github.com/skcc321/deploy_pin/actions/workflows/verify.yml/badge.svg)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/maintainability)](https://codeclimate.com/github/skcc321/deploy_pin/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/c0a9ca97c1f9c0478ffc/test_coverage)](https://codeclimate.com/github/skcc321/deploy_pin/test_coverage)
6
6
 
@@ -21,9 +21,14 @@ deploy_pins is exactly what you need.
21
21
 
22
22
  To generate new task template file
23
23
  ```bash
24
- rails g deploy_pin:task
24
+ rails g deploy_pin:task some_task_title
25
25
  # or
26
- rails g deploy_pin:task --parallel
26
+ rails g deploy_pin:task some_task_title --parallel
27
+ ```
28
+
29
+ Also, you can specify author
30
+ ```bash
31
+ rails g deploy_pin:task some_task_title -a author_name
27
32
  ```
28
33
 
29
34
  To list all pending tasks
@@ -40,11 +45,10 @@ rake deploy_pin:run
40
45
 
41
46
  Please define allowed groups in `config/initializers/deploy_pin.rb`
42
47
  if you want to group tasks around "allowed_group"
43
-
44
48
  ```bash
45
- rails g deploy_pin:task allowed_group
49
+ rails g deploy_pin:task task_title -g allowed_group
46
50
  # or
47
- rails g deploy_pin:task allowed_group --parallel
51
+ rails g deploy_pin:task task_title -g allowed_group --parallel
48
52
  ```
49
53
 
50
54
  To list all pending tasks
data/Rakefile CHANGED
@@ -1,27 +1,7 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
1
+ # frozen_string_literal: true
6
2
 
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'DeployPin'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
3
+ require 'bundler/setup'
16
4
 
17
5
  require 'bundler/gem_tasks'
18
6
 
19
- require 'rake/testtask'
20
-
21
- Rake::TestTask.new(:test) do |t|
22
- t.libs << 'test'
23
- t.pattern = 'test/**/*_test.rb'
24
- t.verbose = false
25
- end
26
-
27
- task default: :test
7
+ import 'test/dummy/Rakefile'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DeployPin::ApplicationRecord < ActiveRecord::Base
2
4
  self.abstract_class = true
3
5
  end
@@ -3,4 +3,3 @@
3
3
  class DeployPin::Record < DeployPin::ApplicationRecord
4
4
  self.table_name = 'deploy_pins'
5
5
  end
6
-
@@ -19,7 +19,11 @@ module DeployPin
19
19
  yield(index, _tasks.count, task, executable)
20
20
 
21
21
  # run if executable
22
- task.run if executable
22
+ if executable
23
+ run_with_timeout(!task.explicit_timeout? && !task.parallel?) do
24
+ task.run
25
+ end
26
+ end
23
27
 
24
28
  # mark each task as done
25
29
  task.mark unless task.done?
@@ -46,7 +50,7 @@ module DeployPin
46
50
  end
47
51
 
48
52
  private
49
-
53
+ # :reek:UtilityFunction
50
54
  def files
51
55
  Dir["#{DeployPin.tasks_path}/*.rb"]
52
56
  end
@@ -64,5 +68,12 @@ module DeployPin
64
68
  def task_criteria
65
69
  @task_criteria ||= DeployPin::TaskCriteria.new(identifiers: identifiers)
66
70
  end
71
+
72
+ # :reek:UtilityFunction and :reek:ControlParameter
73
+ def run_with_timeout(under_timeout, &block)
74
+ return yield unless under_timeout
75
+
76
+ DeployPin::Database.execute_with_timeout(DeployPin.statement_timeout, **{}, &block)
77
+ end
67
78
  end
68
79
  end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeployPin
4
+ module Database
5
+ PG_TIMEOUT_STATEMENT = 'SET statement_timeout TO %s'
6
+ MYSQL_TIMEOUT_STATEMENT = 'SET max_execution_time = %s'
7
+
8
+ extend self
9
+
10
+ # Run a block under a sql maximum timeout.
11
+ #
12
+ # A default timeout will be get from DeployPin.setup
13
+ #
14
+ # # config/initializers/deploy_pin.rb
15
+ # DeployPin.setup do
16
+ # statement_timeout 0.2.second # 200 ms
17
+ # end
18
+ #
19
+ # # <app root>/deploy_pin/20190401135040_task.rb
20
+ # # 20190401135040:I
21
+ # # task_title: Execute some query with timeout
22
+ #
23
+ # # === task code goes down here ===
24
+ # DeployPin::Database::execute_with_timeout do
25
+ # ActiveRecord::Base.connection.execute("select * from shipments;")
26
+ # end
27
+ #
28
+ # A timeout can be passed as param as well:
29
+ #
30
+ # DeployPin::Database::execute_with_timeout 10.minutes do
31
+ # ActiveRecord::Base.connection.execute("select * from shipments;")
32
+ # end
33
+ #
34
+ # In order to connect to multiple databases, pass the +connected_to+ keyword into the params.
35
+ # The +connected_to+ will use the +ActiveRecord::Base.connected_to+.
36
+ # To connect to a replica database, for example:
37
+ #
38
+ # DeployPin::Database::execute_with_timeout 1.seconds, connected_to: { role: :reading } do
39
+ # Shipment.all # Get all record from replica
40
+ # end
41
+ #
42
+ # Or a specific database:
43
+ #
44
+ # DeployPin::Database.execute_with_timeout 30.second, connected_to: { database: :test_mysql } do
45
+ # ActiveRecord::Base.connection.execute("<some mysql query>")
46
+ # end
47
+ def execute_with_timeout(timeout = DeployPin.statement_timeout, **params, &blk)
48
+ raise ArgumentError, 'timeout must be greater than zero' if timeout.to_f <= 0
49
+
50
+ return call_block_under_timeout(timeout, &blk) unless params.key? :connected_to
51
+
52
+ klass = params[:connected_to].key?(:database) ? ActiveRecord::Base : ::ApplicationRecord
53
+ klass.connected_to(**params[:connected_to]) do
54
+ call_block_under_timeout(timeout, &blk)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def call_block_under_timeout(timeout)
61
+ set_max_timeout(timeout)
62
+
63
+ yield
64
+ end
65
+
66
+ def set_max_timeout(timeout)
67
+ timeout_in_milliseconds = timeout.to_f.in_milliseconds.ceil # Make sure is always at least 1. 0 turns this off
68
+
69
+ timeout_statement =
70
+ if postgresql?
71
+ PG_TIMEOUT_STATEMENT
72
+ elsif mysql?
73
+ MYSQL_TIMEOUT_STATEMENT
74
+ end
75
+
76
+ connection.execute timeout_statement % connection.quote(timeout_in_milliseconds)
77
+ end
78
+
79
+ def postgresql?
80
+ connection.adapter_name =~ /postg/i
81
+ end
82
+
83
+ def mysql?
84
+ connection.adapter_name =~ /mysql/i
85
+ end
86
+
87
+ def connection
88
+ ActiveRecord::Base.connection
89
+ end
90
+ end
91
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DeployPin
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace DeployPin
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeployPin
4
+ # Parallel wrapper to run parallel tasks using database statement timeout.
5
+ # This wrapper keeps parallel interface, but running the processes under db statement timeout.
6
+ #
7
+ # In order to use this wrapper, just use call parallel methods with `parallel_`. Ex.:
8
+ # parallel_each(1..2, in_processes: 2, timeout: 0.3.seconds) do |i|
9
+ # puts "Item: #{i}, Worker: #{Parallel.worker_number}"
10
+ # ActiveRecord::Base.connection.execute("<some db query>")
11
+ # end
12
+ #
13
+ # In order to pass more `timeout` options, it requires to pass an array, like:
14
+ # parallel_each(1..2, in_processes: 2, timeout: [0.3.seconds, { connected_to: { role: :reading } }]) do |i|
15
+ # puts "Item: #{i}, Worker: #{Parallel.worker_number}"
16
+ # ActiveRecord::Base.connection.execute("<some db query>")
17
+ # end
18
+ module ParallelWrapper
19
+ PARALLEL_PREFIX = 'parallel_'
20
+
21
+ # :reek:TooManyInstanceVariables
22
+ class ParallelRunner
23
+ def initialize(method_name, *args, &db_block)
24
+ @method_name = method_name
25
+ @db_block = db_block
26
+
27
+ if args.last.is_a?(Hash) && args.last.key?(:timeout)
28
+ @timeout_args = args.pop
29
+ prepare_timeout_args
30
+ end
31
+
32
+ @parallel_args = args
33
+ end
34
+
35
+ def run
36
+ raise 'You must provide at least one argument for parallel methods' if parallel_args.empty?
37
+
38
+ Parallel.send(parallel_method_name, *parallel_args) do |*block_args|
39
+ ActiveRecord::Base.connection_pool.with_connection do
40
+ DeployPin::Database.execute_with_timeout(timeout, **timeout_params) do
41
+ db_block.call(*block_args)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ attr_accessor :method_name, :parallel_args, :db_block
50
+
51
+ def prepare_timeout_args
52
+ timeout = @timeout_args[:timeout]
53
+ if timeout.is_a?(Array)
54
+ @timeout = timeout.shift
55
+ @timeout_params = timeout.first
56
+ else
57
+ @timeout = timeout
58
+ end
59
+ end
60
+
61
+ def timeout
62
+ @timeout ||= DeployPin.statement_timeout
63
+ end
64
+
65
+ def timeout_params
66
+ @timeout_params ||= {}
67
+ end
68
+
69
+ def parallel_method_name
70
+ @parallel_method_name ||= method_name.to_s.gsub(PARALLEL_PREFIX, '').to_sym
71
+ end
72
+ end
73
+
74
+ def method_missing(name, *args, &block)
75
+ return super unless respond_to_missing?(name)
76
+
77
+ ParallelRunner.new(name, *args, &block).run
78
+ end
79
+
80
+ # :reek:ManualDispatch and :reek:BooleanParameter
81
+ def respond_to_missing?(method_name, include_private = false)
82
+ return super unless parallel_prefix_pattern.match? method_name
83
+
84
+ parallel_method_name = method_name.to_s.gsub(PARALLEL_PREFIX, '').to_sym
85
+
86
+ Parallel.respond_to?(parallel_method_name) || super
87
+ end
88
+
89
+ private
90
+
91
+ def parallel_prefix_pattern
92
+ @parallel_prefix_pattern ||= /\A#{PARALLEL_PREFIX}/
93
+ end
94
+ end
95
+ end
@@ -10,7 +10,7 @@ module DeployPin
10
10
  end
11
11
 
12
12
  def self.list(identifiers:)
13
- DeployPin::Collector.new(identifiers: identifiers).list do |index, count, task|
13
+ DeployPin::Collector.new(identifiers: identifiers).list do |index, _count, task|
14
14
  self.print("======= Task ##{index} ========".white)
15
15
 
16
16
  # print details
@@ -18,17 +18,17 @@ module DeployPin
18
18
  self.print("#{key}:\t\t#{value}")
19
19
  end
20
20
 
21
- self.print("")
22
- self.print("<<<")
21
+ self.print('')
22
+ self.print('<<<')
23
23
  self.print task.script.strip.green
24
- self.print(">>>")
25
- self.print("")
24
+ self.print('>>>')
25
+ self.print('')
26
26
  end
27
27
  end
28
28
 
29
29
  def self.summary(identifiers:)
30
30
  # print summary
31
- self.print("======= Summary ========")
31
+ self.print('======= Summary ========')
32
32
  self.print("tasks number: #{DeployPin::Collector.new(identifiers: identifiers).tasks_count}")
33
33
  end
34
34
 
@@ -3,18 +3,24 @@
3
3
  # Task wrapper
4
4
  module DeployPin
5
5
  class Task
6
+ extend ::DeployPin::ParallelWrapper
7
+ include ::DeployPin::ParallelWrapper
8
+
6
9
  attr_reader :file,
7
- :uuid,
8
- :group,
9
- :title,
10
- :script
10
+ :uuid,
11
+ :group,
12
+ :title,
13
+ :script,
14
+ :explicit_timeout
11
15
 
12
16
  def initialize(file)
13
17
  @file = file
14
18
  @uuid = nil
15
19
  @group = nil
16
- @title = ""
17
- @script = ""
20
+ @title = ''
21
+ @script = ''
22
+ @explicit_timeout = false
23
+ @parallel = false
18
24
  end
19
25
 
20
26
  def run
@@ -31,16 +37,27 @@ module DeployPin
31
37
  DeployPin::Record.where(uuid: uuid).exists?
32
38
  end
33
39
 
40
+ def explicit_timeout?
41
+ @explicit_timeout
42
+ end
43
+
44
+ def parallel?
45
+ @parallel
46
+ end
47
+
34
48
  def parse_file
35
49
  File.foreach(file) do |line|
36
50
  case line.strip
37
51
  when /\A# (\d+):(\w+)/
38
- @uuid = $1
39
- @group = $2
52
+ @uuid = Regexp.last_match(1)
53
+ @group = Regexp.last_match(2)
40
54
  when /\A# task_title:(.+)/
41
- @title = $1.strip
55
+ @title = Regexp.last_match(1).strip
42
56
  when /\A[^#].*/
43
57
  @script += line
58
+
59
+ @explicit_timeout = true if line =~ /Database.execute_with_timeout.*/
60
+ @parallel = true if line =~ /[Pp]arallel.*/
44
61
  end
45
62
  end
46
63
  end
@@ -53,16 +70,16 @@ module DeployPin
53
70
  }
54
71
  end
55
72
 
56
- def eql?(task_b)
73
+ def eql?(other)
57
74
  # same script & different uuid
58
- script == task_b.script && uuid != task_b.uuid
75
+ script == other.script && uuid != other.uuid
59
76
  end
60
77
 
61
78
  protected
62
79
 
63
80
  # for sorting
64
- def <=>(task_b)
65
- group_index <=> task_b.group_index
81
+ def <=>(other)
82
+ group_index <=> other.group_index
66
83
  end
67
84
 
68
85
  def group_index
@@ -14,16 +14,16 @@ module DeployPin
14
14
  end
15
15
 
16
16
  def suitable?(task)
17
- task_cover = ->(task, regexp) {
18
- items = identifiers.flat_map {|x| x.to_s.scan(regexp) }.flatten
17
+ task_cover = lambda { |task, regexp|
18
+ items = identifiers.flat_map { |x| x.to_s.scan(regexp) }.flatten
19
19
 
20
20
  items & [task.group, task.uuid]
21
21
  }
22
22
 
23
- return false if task_cover.(task, SKIP_REGEXEP).any?
24
- return true if task_cover.(task, FORCE_REGEXP).any?
23
+ return false if task_cover.call(task, SKIP_REGEXEP).any?
24
+ return true if task_cover.call(task, FORCE_REGEXP).any?
25
25
 
26
- task_cover.(task, COMMON_REGEXP).any? && !task.done?
26
+ task_cover.call(task, COMMON_REGEXP).any? && !task.done?
27
27
  end
28
28
  end
29
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DeployPin
2
- VERSION = '1.2.3'
4
+ VERSION = '1.3.2'
3
5
  end
data/lib/deploy_pin.rb CHANGED
@@ -1,18 +1,23 @@
1
- require "deploy_pin/runner"
2
- require "deploy_pin/collector"
3
- require "deploy_pin/task"
4
- require "deploy_pin/task_criteria"
5
- require "deploy_pin/engine"
6
- require "parallel"
7
- require "ruby-progressbar"
8
- require "colorize"
1
+ # frozen_string_literal: true
2
+
3
+ require 'deploy_pin/runner'
4
+ require 'deploy_pin/collector'
5
+ require 'deploy_pin/parallel_wrapper'
6
+ require 'deploy_pin/task'
7
+ require 'deploy_pin/task_criteria'
8
+ require 'deploy_pin/engine'
9
+ require 'deploy_pin/database'
10
+ require 'parallel'
11
+ require 'ruby-progressbar'
12
+ require 'colorize'
9
13
 
10
14
  module DeployPin
11
- OPTIONS = %i(
15
+ OPTIONS = %i[
12
16
  tasks_path
13
17
  fallback_group
14
18
  groups
15
- )
19
+ statement_timeout
20
+ ].freeze
16
21
 
17
22
  OPTIONS.each do |option|
18
23
  instance_eval %{
@@ -21,7 +26,7 @@ module DeployPin
21
26
 
22
27
  @@#{option} = val
23
28
  end
24
- }
29
+ }, __FILE__, __LINE__ - 6
25
30
  end
26
31
 
27
32
  def self.setup(&block)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DeployPin::InstallGenerator < Rails::Generators::Base
2
4
  include Rails::Generators::Migration
3
5
 
4
6
  source_root File.expand_path('templates', __dir__)
5
- desc "Add the migration & initializer for DeployPin"
7
+ desc 'Add the migration & initializer for DeployPin'
6
8
 
7
9
  def self.next_migration_number(path)
8
10
  next_migration_number = current_migration_number(path) + 1
@@ -10,10 +12,10 @@ class DeployPin::InstallGenerator < Rails::Generators::Base
10
12
  end
11
13
 
12
14
  def copy_migrations
13
- migration_template "create_deploy_pins.rb", "db/migrate/create_deploy_pins.rb"
15
+ migration_template 'create_deploy_pins.rb', 'db/migrate/create_deploy_pins.rb'
14
16
  end
15
17
 
16
18
  def copy_initializer
17
- template "deploy_pin.rb", "config/initializers/deploy_pin.rb"
19
+ template 'deploy_pin.rb', 'config/initializers/deploy_pin.rb'
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateDeployPins < ActiveRecord::Migration[5.2]
2
4
  def change
3
5
  create_table :deploy_pins do |t|
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  DeployPin.setup do
4
- tasks_path "lib/deploy_pin"
5
- groups ["I", "II", "III"]
6
- fallback_group "II"
4
+ tasks_path 'lib/deploy_pin'
5
+ groups %w[I II III]
6
+ fallback_group 'II'
7
+
8
+ statement_timeout 10.minutes
7
9
  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,5 +1,7 @@
1
- # <%= @uuid %>:<%= group %>
2
- # task_title: super duper task
1
+ # frozen_string_literal: true
2
+
3
+ # <%= @uuid %>:<%= @group %>
4
+ # task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
3
5
 
4
6
  # === parallel task code goes down here ===
5
7
  10.times { DeployPin::Record.create(uuid: "hello") }
@@ -9,4 +11,10 @@ Parallel.each(DeployPin::Record.where(uuid: "hello"), progress: "Doing stuff") d
9
11
  pin.update_attribute(:uuid, "new uuid")
10
12
  end
11
13
  sleep(0.2)
14
+
15
+ # DeployPin::Database::execute_with_timeout 10.minutes do
16
+ # ActiveRecord::Base.connection.execute("select * from shipments;")
17
+ # or
18
+ # Shipment.all
19
+ # end
12
20
  end
@@ -1,7 +1,15 @@
1
- # <%= @uuid %>:<%= group %>
2
- # task_title: super duper task
1
+ # frozen_string_literal: true
2
+
3
+ # <%= @uuid %>:<%= @group %>
4
+ # task_title: <%= @author ? "@#{@author} #{title.titleize}" : "#{title.titleize}" %>
3
5
 
4
6
  # === task code goes down here ===
5
7
  progressbar = ProgressBar.create(title: "Doing stuff", total: 20, format: '%t |%E | %B | %a')
6
8
 
7
9
  20.times { progressbar.increment; sleep(0.2) }
10
+
11
+ # DeployPin::Database::execute_with_timeout 10.minutes do
12
+ # ActiveRecord::Base.connection.execute("select * from shipments;")
13
+ # or
14
+ # Shipment.all
15
+ # end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :deploy_pin do
2
- desc "run pending tasks"
3
- task :run, [:identifiers] => :environment do |t, args|
4
+ desc 'run pending tasks'
5
+ task :run, [:identifiers] => :environment do |_t, args|
4
6
  identifiers = args.identifiers
5
7
  attributes = identifiers.nil? ? DeployPin.groups : identifiers.split(/\s*,\s*/)
6
8
 
7
9
  DeployPin::Runner.run(identifiers: attributes)
8
10
  end
9
11
 
10
- task :list, [:identifiers] => :environment do |t, args|
12
+ task :list, [:identifiers] => :environment do |_t, args|
11
13
  args.with_defaults(identifiers: DeployPin.groups)
12
14
 
13
- DeployPin::Runner.list(args)
14
- DeployPin::Runner.summary(args)
15
+ DeployPin::Runner.list(**args)
16
+ DeployPin::Runner.summary(**args)
15
17
  end
16
18
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
- - rafael
8
- autorequire:
7
+ - Viktor Sych
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parallel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,41 +39,41 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-progressbar
42
+ name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.10'
47
+ version: 6.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.10'
54
+ version: 6.0.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: ruby-progressbar
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 12.1.0
61
+ version: '1.10'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 12.1.0
68
+ version: '1.10'
69
69
  - !ruby/object:Gem::Dependency
70
- name: colorize
70
+ name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -81,95 +81,75 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.16.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.16.0
97
- - !ruby/object:Gem::Dependency
98
- name: bundler
84
+ name: minitest
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - "~>"
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: '1.17'
89
+ version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - "~>"
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: '1.17'
96
+ version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: pry
98
+ name: mysql2
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - "~>"
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
- version: '0.12'
103
+ version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
- - - "~>"
108
+ - - ">="
123
109
  - !ruby/object:Gem::Version
124
- version: '0.12'
110
+ version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: minitest
112
+ name: pg
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
- - - "~>"
115
+ - - ">="
130
116
  - !ruby/object:Gem::Version
131
- version: '5.0'
117
+ version: '0'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
- - - "~>"
122
+ - - ">="
137
123
  - !ruby/object:Gem::Version
138
- version: '5.0'
124
+ version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
- name: mysql2
126
+ name: pry
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - "~>"
129
+ - - ">="
144
130
  - !ruby/object:Gem::Version
145
- version: 0.5.2
131
+ version: '0'
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
- - - "~>"
136
+ - - ">="
151
137
  - !ruby/object:Gem::Version
152
- version: 0.5.2
138
+ version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
- name: pg
140
+ name: rubocop
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.18'
160
143
  - - ">="
161
144
  - !ruby/object:Gem::Version
162
- version: 0.18.4
145
+ version: '0'
163
146
  type: :development
164
147
  prerelease: false
165
148
  version_requirements: !ruby/object:Gem::Requirement
166
149
  requirements:
167
- - - "~>"
168
- - !ruby/object:Gem::Version
169
- version: '0.18'
170
150
  - - ">="
171
151
  - !ruby/object:Gem::Version
172
- version: 0.18.4
152
+ version: '0'
173
153
  description: pin some task around deployment to execute them during deployment circle
174
154
  email:
175
155
  - skcc321@gmail.com
@@ -184,7 +164,9 @@ files:
184
164
  - app/models/deploy_pin/record.rb
185
165
  - lib/deploy_pin.rb
186
166
  - lib/deploy_pin/collector.rb
167
+ - lib/deploy_pin/database.rb
187
168
  - lib/deploy_pin/engine.rb
169
+ - lib/deploy_pin/parallel_wrapper.rb
188
170
  - lib/deploy_pin/runner.rb
189
171
  - lib/deploy_pin/task.rb
190
172
  - lib/deploy_pin/task_criteria.rb
@@ -203,7 +185,7 @@ licenses:
203
185
  - MIT
204
186
  metadata:
205
187
  allowed_push_host: https://rubygems.org
206
- post_install_message:
188
+ post_install_message:
207
189
  rdoc_options: []
208
190
  require_paths:
209
191
  - lib
@@ -218,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
200
  - !ruby/object:Gem::Version
219
201
  version: '0'
220
202
  requirements: []
221
- rubygems_version: 3.0.6
222
- signing_key:
203
+ rubygems_version: 3.2.22
204
+ signing_key:
223
205
  specification_version: 4
224
206
  summary: pin some task around deployment
225
207
  test_files: []