sidekiq-runner 0.1.4 → 0.2.2
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 +16 -4
- data/lib/sidekiq-runner/sidekiq_configuration.rb +1 -5
- data/lib/sidekiq-runner/sidekiq_instance.rb +19 -24
- data/lib/sidekiq-runner/version.rb +1 -1
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ab39cb1000c541dae57dc976f97fc96002d4a57c50c00e7161f8885646ba381
|
4
|
+
data.tar.gz: 03de0934038502d732faaa2761c6b0a05bf03dc316fd0b6222f62fd021861881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68a6a2a2876e21a93007082e5ca3ba60fbf6ee71481e631d09cde639d2d6a357b36339bbcec17289123fccdb8c21297ca43d4ba6333d28b38cb0d7ce6ccf0582
|
7
|
+
data.tar.gz: bc64fedeb29a0152532bbcd6ab7bd9213a36aa812c07cf6e8b4191a699a62828c60bad442f200c0fe73797133eb4b17d4daa61056a1887bf3e25dad5164875da
|
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,13 +19,15 @@ 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
|
-
#
|
21
|
-
w.
|
22
|
-
w.
|
28
|
+
# Set uid/gid if requested.
|
29
|
+
w.uid = skiq.uid if skiq.uid
|
30
|
+
w.gid = skiq.gid if skiq.gid
|
23
31
|
|
24
32
|
# Working directory has to be set properly.
|
25
33
|
# Be aware that by default, God sets the working directory to / (root dir).
|
@@ -72,6 +80,10 @@ sidekiq_config.each do |name, skiq|
|
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
83
|
+
if skiq.config_blocks.length > 0
|
84
|
+
skiq.config_blocks.each { |blk| blk.call(w) }
|
85
|
+
end
|
86
|
+
|
75
87
|
w.lifecycle do |on|
|
76
88
|
on.condition(:flapping) do |c|
|
77
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
|
-
CONFIG_FILE_ATTRIBUTES = [:concurrency, :verbose, :pidfile, :logfile, :tag, :rbtrace]
|
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 = []
|
@@ -24,15 +23,23 @@ module SidekiqRunner
|
|
24
23
|
@verbose = false
|
25
24
|
@tag = name
|
26
25
|
@rbtrace = false
|
26
|
+
@uid = nil
|
27
|
+
@gid = nil
|
28
|
+
@config_blocks = []
|
27
29
|
end
|
28
30
|
|
29
31
|
def add_queue(queue_name, weight = 1)
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
+
|
33
36
|
@queues << [queue_name, weight]
|
34
37
|
end
|
35
38
|
|
39
|
+
def god_config(&block)
|
40
|
+
@config_blocks << block
|
41
|
+
end
|
42
|
+
|
36
43
|
def merge_config_file!(yml)
|
37
44
|
# Get global configuration options.
|
38
45
|
SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
|
@@ -40,7 +47,7 @@ module SidekiqRunner
|
|
40
47
|
end
|
41
48
|
|
42
49
|
# Override with instance-specific options.
|
43
|
-
if (syml = yml[@name.to_sym]) &&
|
50
|
+
if (syml = yml[@name.to_sym]) && syml.is_a?(Hash)
|
44
51
|
syml = Hash[syml.map { |k, v| [k.to_sym, v] }]
|
45
52
|
|
46
53
|
SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
|
@@ -50,8 +57,8 @@ module SidekiqRunner
|
|
50
57
|
end
|
51
58
|
|
52
59
|
def sane?
|
53
|
-
|
54
|
-
|
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
|
55
62
|
end
|
56
63
|
|
57
64
|
def build_start_command
|
@@ -59,33 +66,21 @@ module SidekiqRunner
|
|
59
66
|
|
60
67
|
cmd = []
|
61
68
|
cmd << 'bundle exec' if bundle_env
|
62
|
-
cmd << (rbtrace ? File.expand_path('
|
63
|
-
cmd << '-d'
|
69
|
+
cmd << (rbtrace ? File.expand_path('../../script/sidekiq_rbtrace', __dir__) : 'sidekiq')
|
64
70
|
cmd << "-c #{concurrency}"
|
65
71
|
cmd << '-v' if verbose
|
66
|
-
cmd << "-L #{logfile}"
|
67
72
|
cmd << "-P #{pidfile}"
|
68
73
|
cmd << "-e #{Rails.env}" if defined?(Rails)
|
69
74
|
cmd << "-r #{requirefile}" if requirefile
|
70
75
|
cmd << "-g '#{tag}'"
|
71
76
|
|
72
77
|
queues.each do |q, w|
|
73
|
-
cmd << "-q #{q},#{w
|
78
|
+
cmd << "-q #{q},#{w}"
|
74
79
|
end
|
75
80
|
|
76
81
|
cmd.join(' ')
|
77
82
|
end
|
78
83
|
|
79
|
-
def build_stop_command(timeout)
|
80
|
-
cmd = []
|
81
|
-
cmd << (bundle_env ? 'bundle exec sidekiqctl' : 'sidekiqctl')
|
82
|
-
cmd << 'stop'
|
83
|
-
cmd << pidfile
|
84
|
-
cmd << timeout
|
85
|
-
|
86
|
-
cmd.join(' ')
|
87
|
-
end
|
88
|
-
|
89
84
|
private
|
90
85
|
|
91
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.2
|
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-04-06 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,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
|