sidekiq-runner 0.1.6 → 0.2.0
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 +15 -4
- data/lib/sidekiq-runner/god_configuration.rb +9 -1
- data/lib/sidekiq-runner/sidekiq.god +9 -5
- data/lib/sidekiq-runner/sidekiq_configuration.rb +1 -5
- data/lib/sidekiq-runner/sidekiq_instance.rb +10 -22
- data/lib/sidekiq-runner/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8918e2e7486207c0a59ae645ec003d7ce1de255ba8e60e48ae9265e3db829b9
|
4
|
+
data.tar.gz: 7931bf1755ef7b945443ea9a6b9c73199e88b3ad5d05e0975baf9b4cd7798480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf8d8f5617fa3eea88088bc14202ccb52a252e4c2e2ba9b7c53c455a9b6929e2218668e5a1b1790c2af42246dae8572b942a65ea645b242a8b53fede15fbad99
|
7
|
+
data.tar.gz: 861b4a172a2c35d738e12b178b9550b9df09d927cf1772a1a3866fc6564ba162d3aad5cb3337a5e21742e86ad417b6d97df2c5991c015031a1db8c41e7622204
|
data/lib/sidekiq-runner.rb
CHANGED
@@ -48,6 +48,17 @@ 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
|
+
sidekiq_config.each_key do |name|
|
58
|
+
God::CLI::Command.new('restart', god_config.options, ['', name]) if sidekiq_instances.empty? || sidekiq_instances.include?(name.to_sym)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
51
62
|
def self.running?
|
52
63
|
god_alive? GodConfiguration.get
|
53
64
|
end
|
@@ -86,12 +97,12 @@ module SidekiqRunner
|
|
86
97
|
yield if block_given?
|
87
98
|
|
88
99
|
rescue SystemExit => e
|
89
|
-
|
100
|
+
sidekiq_cb = e.success? ? "#{action}_success_cb" : "#{action}_error_cb"
|
90
101
|
ensure
|
91
102
|
if [:start, :stop].include? action
|
92
|
-
|
93
|
-
|
94
|
-
|
103
|
+
sidekiq_cb = "#{action}_success_cb" unless sidekiq_cb
|
104
|
+
sidekiq_cb = sidekiq_config.send(sidekiq_cb.to_sym)
|
105
|
+
sidekiq_cb.call if sidekiq_cb
|
95
106
|
end
|
96
107
|
end
|
97
108
|
end
|
@@ -18,6 +18,8 @@ module SidekiqRunner
|
|
18
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
|
@@ -36,6 +38,12 @@ module SidekiqRunner
|
|
36
38
|
# This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock" and the pidfile name
|
37
39
|
# Change this in the configuration file to be able to run multiple instances of god.
|
38
40
|
@port = 17165
|
41
|
+
|
42
|
+
@generic_watchers = []
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_generic(&blk)
|
46
|
+
@generic_watchers << blk
|
39
47
|
end
|
40
48
|
|
41
49
|
def options
|
@@ -64,7 +72,7 @@ module SidekiqRunner
|
|
64
72
|
end
|
65
73
|
|
66
74
|
def create_directories!
|
67
|
-
FileUtils.mkdir_p(File.dirname(log_file))
|
75
|
+
FileUtils.mkdir_p(File.dirname(log_file)) if log_file
|
68
76
|
end
|
69
77
|
|
70
78
|
%w(start stop).each do |action|
|
@@ -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
|
@@ -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,6 +1,5 @@
|
|
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
|
|
@@ -10,7 +9,7 @@ module SidekiqRunner
|
|
10
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 = []
|
@@ -30,9 +29,10 @@ module SidekiqRunner
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def add_queue(queue_name, weight = 1)
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
+
|
36
36
|
@queues << [queue_name, weight]
|
37
37
|
end
|
38
38
|
|
@@ -47,7 +47,7 @@ module SidekiqRunner
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Override with instance-specific options.
|
50
|
-
if (syml = yml[@name.to_sym]) &&
|
50
|
+
if (syml = yml[@name.to_sym]) && syml.is_a?(Hash)
|
51
51
|
syml = Hash[syml.map { |k, v| [k.to_sym, v] }]
|
52
52
|
|
53
53
|
SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
|
@@ -57,8 +57,8 @@ module SidekiqRunner
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def sane?
|
60
|
-
|
61
|
-
|
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
|
62
62
|
end
|
63
63
|
|
64
64
|
def build_start_command
|
@@ -66,33 +66,21 @@ module SidekiqRunner
|
|
66
66
|
|
67
67
|
cmd = []
|
68
68
|
cmd << 'bundle exec' if bundle_env
|
69
|
-
cmd << (rbtrace ? File.expand_path('
|
70
|
-
cmd << '-d'
|
69
|
+
cmd << (rbtrace ? File.expand_path('../../script/sidekiq_rbtrace', __dir__) : 'sidekiq')
|
71
70
|
cmd << "-c #{concurrency}"
|
72
71
|
cmd << '-v' if verbose
|
73
|
-
cmd << "-L #{logfile}"
|
74
72
|
cmd << "-P #{pidfile}"
|
75
73
|
cmd << "-e #{Rails.env}" if defined?(Rails)
|
76
74
|
cmd << "-r #{requirefile}" if requirefile
|
77
75
|
cmd << "-g '#{tag}'"
|
78
76
|
|
79
77
|
queues.each do |q, w|
|
80
|
-
cmd << "-q #{q},#{w
|
78
|
+
cmd << "-q #{q},#{w}"
|
81
79
|
end
|
82
80
|
|
83
81
|
cmd.join(' ')
|
84
82
|
end
|
85
83
|
|
86
|
-
def build_stop_command(timeout)
|
87
|
-
cmd = []
|
88
|
-
cmd << (bundle_env ? 'bundle exec sidekiqctl' : 'sidekiqctl')
|
89
|
-
cmd << 'stop'
|
90
|
-
cmd << pidfile
|
91
|
-
cmd << timeout
|
92
|
-
|
93
|
-
cmd.join(' ')
|
94
|
-
end
|
95
|
-
|
96
84
|
private
|
97
85
|
|
98
86
|
def create_directories!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FlavourSys Technology GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
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,6 +38,20 @@ 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
57
|
email: technology@flavoursys.com
|
@@ -73,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
87
|
version: '0'
|
74
88
|
requirements: []
|
75
89
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.7.6.2
|
77
91
|
signing_key:
|
78
92
|
specification_version: 4
|
79
93
|
summary: Sidekiq configuration and rake tasks
|