sidekiq-runner 0.1.5 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/sidekiq-runner.rb +25 -7
- data/lib/sidekiq-runner/god_configuration.rb +21 -3
- data/lib/sidekiq-runner/sidekiq.god +13 -5
- data/lib/sidekiq-runner/sidekiq_configuration.rb +1 -5
- data/lib/sidekiq-runner/sidekiq_instance.rb +16 -23
- data/lib/sidekiq-runner/version.rb +1 -1
- metadata +24 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e067bdc80524b99f47efbf036f234ca76e188bccee9a1322d0e346342e95852
|
4
|
+
data.tar.gz: b55ec3f9158a9d1ee2ef21bd4986b464d1fc57d7dc7a07e23721bca815eb9b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b178d88d141966a5086c278e76b6767683e07c294377087cb4f709b4c374ce5fc97ccf83598bde69218241782aabf0033b7cfbefaf357db59b63ff05d2ec469
|
7
|
+
data.tar.gz: d5305fd05a3bad32b5da4e9924ad91fa04072934fef70caeecdf7b7a2c4ebd7a4b18bff2cbbacb8baf60f6d45cf846a61ba40d527b4de24442f58ec47f4eb6d5
|
data/lib/sidekiq-runner.rb
CHANGED
@@ -17,7 +17,7 @@ module SidekiqRunner
|
|
17
17
|
|
18
18
|
abort 'God is already running.' if god_alive?(god_config)
|
19
19
|
|
20
|
-
run(:start, sidekiq_config) do
|
20
|
+
run(:start, sidekiq_config, god_config) do
|
21
21
|
$0 = "SidekiqRunner/God (#{god_config.process_name})"
|
22
22
|
|
23
23
|
puts 'Starting god.'
|
@@ -31,7 +31,7 @@ module SidekiqRunner
|
|
31
31
|
def self.stop
|
32
32
|
sidekiq_config, god_config = SidekiqConfiguration.get, GodConfiguration.get
|
33
33
|
|
34
|
-
run(:stop, sidekiq_config) do
|
34
|
+
run(:stop, sidekiq_config, god_config) do
|
35
35
|
God::EventHandler.load
|
36
36
|
|
37
37
|
if god_alive?(god_config)
|
@@ -48,6 +48,19 @@ module SidekiqRunner
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def self.restart(sidekiq_instances: [])
|
52
|
+
sidekiq_config = SidekiqConfiguration.get
|
53
|
+
god_config = GodConfiguration.get
|
54
|
+
|
55
|
+
return unless god_alive?(god_config)
|
56
|
+
|
57
|
+
run(:restart, sidekiq_config, god_config) do
|
58
|
+
sidekiq_config.each_key do |name|
|
59
|
+
God::CLI::Command.new('restart', god_config.options, ['', name]) if sidekiq_instances.empty? || sidekiq_instances.include?(name.to_sym)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
51
64
|
def self.running?
|
52
65
|
god_alive? GodConfiguration.get
|
53
66
|
end
|
@@ -69,7 +82,7 @@ module SidekiqRunner
|
|
69
82
|
true
|
70
83
|
end
|
71
84
|
|
72
|
-
def self.run(action, sidekiq_config)
|
85
|
+
def self.run(action, sidekiq_config, god_config)
|
73
86
|
begin
|
74
87
|
|
75
88
|
# Use this flag to actually load all of the god infrastructure.
|
@@ -77,16 +90,21 @@ module SidekiqRunner
|
|
77
90
|
require 'god'
|
78
91
|
require 'god/cli/run'
|
79
92
|
|
93
|
+
if [:start, :stop].include? action
|
94
|
+
cb = god_config.send("before_#{action}_cb".to_sym)
|
95
|
+
cb.call if cb
|
96
|
+
end
|
97
|
+
|
80
98
|
# Peform the action.
|
81
99
|
yield if block_given?
|
82
100
|
|
83
101
|
rescue SystemExit => e
|
84
|
-
|
102
|
+
sidekiq_cb = e.success? ? "#{action}_success_cb" : "#{action}_error_cb"
|
85
103
|
ensure
|
86
104
|
if [:start, :stop].include? action
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
sidekiq_cb = "#{action}_success_cb" unless sidekiq_cb
|
106
|
+
sidekiq_cb = sidekiq_config.send(sidekiq_cb.to_sym)
|
107
|
+
sidekiq_cb.call if sidekiq_cb
|
90
108
|
end
|
91
109
|
end
|
92
110
|
end
|
@@ -15,9 +15,11 @@ module SidekiqRunner
|
|
15
15
|
RUNNER_ATTRIBUTES = [:config_file, :daemonize, :port, :syslog, :events]
|
16
16
|
RUNNER_ATTRIBUTES.each { |att| attr_accessor att }
|
17
17
|
|
18
|
-
CONFIG_FILE_ATTRIBUTES = [:process_name, :interval, :stop_timeout, :log_file, :maximum_memory_usage, :pid]
|
18
|
+
CONFIG_FILE_ATTRIBUTES = [:process_name, :interval, :stop_timeout, :log_file, :log_level, :maximum_memory_usage, :pid]
|
19
19
|
CONFIG_FILE_ATTRIBUTES.each { |att| attr_accessor att }
|
20
20
|
|
21
|
+
attr_reader :generic_watchers
|
22
|
+
|
21
23
|
def initialize
|
22
24
|
@process_name = 'sidekiq'
|
23
25
|
@interval = 30
|
@@ -31,10 +33,17 @@ module SidekiqRunner
|
|
31
33
|
@syslog = true
|
32
34
|
@events = true
|
33
35
|
@pid = nil
|
36
|
+
@log_level = :warn
|
34
37
|
|
35
38
|
# This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock" and the pidfile name
|
36
39
|
# Change this in the configuration file to be able to run multiple instances of god.
|
37
40
|
@port = 17165
|
41
|
+
|
42
|
+
@generic_watchers = []
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_generic(&blk)
|
46
|
+
@generic_watchers << blk
|
38
47
|
end
|
39
48
|
|
40
49
|
def options
|
@@ -47,7 +56,8 @@ module SidekiqRunner
|
|
47
56
|
events: @events,
|
48
57
|
config: File.expand_path("../sidekiq.god", __FILE__),
|
49
58
|
log: @log_file,
|
50
|
-
pid: @pid
|
59
|
+
pid: @pid,
|
60
|
+
log_level: @log_level
|
51
61
|
}
|
52
62
|
end
|
53
63
|
|
@@ -62,7 +72,15 @@ module SidekiqRunner
|
|
62
72
|
end
|
63
73
|
|
64
74
|
def create_directories!
|
65
|
-
FileUtils.mkdir_p(File.dirname(log_file))
|
75
|
+
FileUtils.mkdir_p(File.dirname(log_file)) if log_file
|
76
|
+
end
|
77
|
+
|
78
|
+
%w(start stop).each do |action|
|
79
|
+
attr_reader "before_#{action}_cb".to_sym
|
80
|
+
|
81
|
+
define_method("before_#{action}") do |&block|
|
82
|
+
instance_variable_set("@before_#{action}_cb".to_sym, block)
|
83
|
+
end
|
66
84
|
end
|
67
85
|
end
|
68
86
|
end
|
@@ -6,6 +6,12 @@ god_config = SidekiqRunner::GodConfiguration.get
|
|
6
6
|
|
7
7
|
God.terminate_timeout = god_config.stop_timeout + 10
|
8
8
|
|
9
|
+
god_config.generic_watchers.each do |block|
|
10
|
+
God.watch do |w|
|
11
|
+
block.call(w)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
sidekiq_config.each do |name, skiq|
|
10
16
|
God.watch do |w|
|
11
17
|
w.name = name
|
@@ -13,14 +19,12 @@ sidekiq_config.each do |name, skiq|
|
|
13
19
|
# Set start command.
|
14
20
|
w.start = skiq.build_start_command
|
15
21
|
|
22
|
+
# Set logfile
|
23
|
+
w.log = skiq.logfile
|
24
|
+
|
16
25
|
# Set stop command.
|
17
|
-
w.stop = skiq.build_stop_command(god_config.stop_timeout)
|
18
26
|
w.stop_timeout = god_config.stop_timeout
|
19
27
|
|
20
|
-
# Make sure the pidfile is deleted as sidekiqctl does not delete stale pidfiles.
|
21
|
-
w.pid_file = skiq.pidfile
|
22
|
-
w.behavior(:clean_pid_file)
|
23
|
-
|
24
28
|
# Set uid/gid if requested.
|
25
29
|
w.uid = skiq.uid if skiq.uid
|
26
30
|
w.gid = skiq.gid if skiq.gid
|
@@ -76,6 +80,10 @@ sidekiq_config.each do |name, skiq|
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
83
|
+
if skiq.config_blocks.length > 0
|
84
|
+
skiq.config_blocks.each { |blk| blk.call(w) }
|
85
|
+
end
|
86
|
+
|
79
87
|
w.lifecycle do |on|
|
80
88
|
on.condition(:flapping) do |c|
|
81
89
|
c.to_state = [:start, :restart] # If this watch is started or restarted...
|
@@ -12,7 +12,7 @@ module SidekiqRunner
|
|
12
12
|
def initialize
|
13
13
|
@config_file =
|
14
14
|
if defined?(Rails)
|
15
|
-
File.join(Rails.root, 'config', 'sidekiq.yml')
|
15
|
+
File.join(Rails.root, 'config', 'sidekiq.yml')
|
16
16
|
else
|
17
17
|
File.join(Dir.pwd, 'config', 'sidekiq.yml')
|
18
18
|
end
|
@@ -86,8 +86,6 @@ module SidekiqRunner
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def merge_config_file!
|
89
|
-
sidekiqs_common_config = {}
|
90
|
-
|
91
89
|
yml = File.exist?(config_file) ? YAML.load_file(config_file) : {}
|
92
90
|
yml = Hash[yml.map { |k, v| [k.to_sym, v] }]
|
93
91
|
|
@@ -96,8 +94,6 @@ module SidekiqRunner
|
|
96
94
|
|
97
95
|
def sane?
|
98
96
|
fail 'No sidekiq instances defined. Nothing to run.' if @sidekiqs.empty?
|
99
|
-
fail 'Sidekiq instances with the same pidfile found.' if @sidekiqs.values.map(&:pidfile).uniq.size < @sidekiqs.size
|
100
|
-
fail 'Sidekiq instances with the same logfile found.' if @sidekiqs.values.map(&:logfile).uniq.size < @sidekiqs.size
|
101
97
|
|
102
98
|
@sidekiqs.each_value { |skiq| skiq.sane? }
|
103
99
|
end
|
@@ -1,16 +1,15 @@
|
|
1
1
|
module SidekiqRunner
|
2
2
|
class SidekiqInstance
|
3
|
-
|
4
3
|
RUNNER_ATTRIBUTES = [:bundle_env, :chdir, :requirefile]
|
5
4
|
RUNNER_ATTRIBUTES.each { |att| attr_accessor att }
|
6
5
|
|
7
6
|
CONFIG_FILE_ATTRIBUTES = [:concurrency, :verbose, :pidfile, :logfile, :tag, :rbtrace, :uid, :gid]
|
8
7
|
CONFIG_FILE_ATTRIBUTES.each { |att| attr_accessor att }
|
9
8
|
|
10
|
-
attr_reader :name, :queues
|
9
|
+
attr_reader :name, :queues, :config_blocks
|
11
10
|
|
12
11
|
def initialize(name)
|
13
|
-
|
12
|
+
raise "No sidekiq instance name given!" if name.empty?
|
14
13
|
|
15
14
|
@name = name
|
16
15
|
@queues = []
|
@@ -26,15 +25,21 @@ module SidekiqRunner
|
|
26
25
|
@rbtrace = false
|
27
26
|
@uid = nil
|
28
27
|
@gid = nil
|
28
|
+
@config_blocks = []
|
29
29
|
end
|
30
30
|
|
31
31
|
def add_queue(queue_name, weight = 1)
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
raise "Cannot add the queue. The name is empty!" if queue_name.empty?
|
33
|
+
raise "Cannot add the queue. The weight is not an integer!" unless weight.is_a? Integer
|
34
|
+
raise "Cannot add the queue. The queue with \"#{queue_name}\" name already exist" if @queues.any? { |q| q.first == queue_name }
|
35
|
+
|
35
36
|
@queues << [queue_name, weight]
|
36
37
|
end
|
37
38
|
|
39
|
+
def god_config(&block)
|
40
|
+
@config_blocks << block
|
41
|
+
end
|
42
|
+
|
38
43
|
def merge_config_file!(yml)
|
39
44
|
# Get global configuration options.
|
40
45
|
SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
|
@@ -42,7 +47,7 @@ module SidekiqRunner
|
|
42
47
|
end
|
43
48
|
|
44
49
|
# Override with instance-specific options.
|
45
|
-
if (syml = yml[@name.to_sym]) &&
|
50
|
+
if (syml = yml[@name.to_sym]) && syml.is_a?(Hash)
|
46
51
|
syml = Hash[syml.map { |k, v| [k.to_sym, v] }]
|
47
52
|
|
48
53
|
SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
|
@@ -52,8 +57,8 @@ module SidekiqRunner
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def sane?
|
55
|
-
|
56
|
-
|
60
|
+
raise "No queues given for #{@name}!" if @queues.empty?
|
61
|
+
raise "No requirefile given for #{@name} and not in Rails environment!" if !defined?(Rails) && !requirefile
|
57
62
|
end
|
58
63
|
|
59
64
|
def build_start_command
|
@@ -61,33 +66,21 @@ module SidekiqRunner
|
|
61
66
|
|
62
67
|
cmd = []
|
63
68
|
cmd << 'bundle exec' if bundle_env
|
64
|
-
cmd << (rbtrace ? File.expand_path('
|
65
|
-
cmd << '-d'
|
69
|
+
cmd << (rbtrace ? File.expand_path('../../script/sidekiq_rbtrace', __dir__) : 'sidekiq')
|
66
70
|
cmd << "-c #{concurrency}"
|
67
71
|
cmd << '-v' if verbose
|
68
|
-
cmd << "-L #{logfile}"
|
69
72
|
cmd << "-P #{pidfile}"
|
70
73
|
cmd << "-e #{Rails.env}" if defined?(Rails)
|
71
74
|
cmd << "-r #{requirefile}" if requirefile
|
72
75
|
cmd << "-g '#{tag}'"
|
73
76
|
|
74
77
|
queues.each do |q, w|
|
75
|
-
cmd << "-q #{q},#{w
|
78
|
+
cmd << "-q #{q},#{w}"
|
76
79
|
end
|
77
80
|
|
78
81
|
cmd.join(' ')
|
79
82
|
end
|
80
83
|
|
81
|
-
def build_stop_command(timeout)
|
82
|
-
cmd = []
|
83
|
-
cmd << (bundle_env ? 'bundle exec sidekiqctl' : 'sidekiqctl')
|
84
|
-
cmd << 'stop'
|
85
|
-
cmd << pidfile
|
86
|
-
cmd << timeout
|
87
|
-
|
88
|
-
cmd.join(' ')
|
89
|
-
end
|
90
|
-
|
91
84
|
private
|
92
85
|
|
93
86
|
def create_directories!
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Projective Technology GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: god
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,9 +38,23 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sidekiq
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
41
55
|
description: Provide an easy way to configure, start, and monitor all your Sidekiq
|
42
56
|
processes
|
43
|
-
email: technology@
|
57
|
+
email: technology@projective.io
|
44
58
|
executables: []
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
@@ -53,7 +67,7 @@ files:
|
|
53
67
|
- lib/sidekiq-runner/tasks.rb
|
54
68
|
- lib/sidekiq-runner/version.rb
|
55
69
|
- script/sidekiq_rbtrace
|
56
|
-
homepage: https://github.com/
|
70
|
+
homepage: https://github.com/projectivetech/sidekiq-runner
|
57
71
|
licenses:
|
58
72
|
- MIT
|
59
73
|
metadata: {}
|
@@ -72,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
86
|
- !ruby/object:Gem::Version
|
73
87
|
version: '0'
|
74
88
|
requirements: []
|
75
|
-
|
76
|
-
rubygems_version: 2.4.5
|
89
|
+
rubygems_version: 3.2.5
|
77
90
|
signing_key:
|
78
91
|
specification_version: 4
|
79
92
|
summary: Sidekiq configuration and rake tasks
|