sidekiq-runner 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: ca0010af09c70a83fb3d9a7e19bb1fab9ab8c2d7
4
- data.tar.gz: 2a56f515a2abc4174eca0e222161facc262d45bc
3
+ metadata.gz: a964d456a2836681b258bc3cc4052fbc26dce0dd
4
+ data.tar.gz: e931c16b0328eff55bcd3a09cba5de69e73e6e55
5
5
  SHA512:
6
- metadata.gz: 30074809519b45508efeaa338146c1e601065f1e77c4d7df375d19e1ef67dfc4af440475f2643eb53146b3185092bd0ea361b944aa1683717471cfa2fa03c23f
7
- data.tar.gz: c03238275cb23d3a27628abca14a087a22a0a9a519355525103392e05aed0f4039e87a3f7078fe8fdbb26d6c09e5057a434f1eae3d02d73ef0f5ea6d1c441eb8
6
+ metadata.gz: 38bbf8146a5b13e4ab5c22891c5ccf49a206e3f148273c8d813ae6e87d3f290096fb2df3c4af9877e7af2e25c7f8e2891bf34e3b077a3aad16b2295858428476
7
+ data.tar.gz: b58ed792d28ce63e3ece4538a53a832b0cbef7ff9e2cc85c3f41ade78fdf3531df9e63f743e7e52301189f00c6254e9901c0f69141424a5de1c02616a7be53b4
@@ -1,6 +1,6 @@
1
+ require 'sidekiq-runner/sidekiq_instance'
1
2
  require 'sidekiq-runner/sidekiq_configuration'
2
3
  require 'sidekiq-runner/god_configuration'
3
- require 'sidekiq-runner/sidekiq_instance'
4
4
  require 'sidekiq-runner/version'
5
5
 
6
6
  module SidekiqRunner
@@ -13,11 +13,9 @@ module SidekiqRunner
13
13
  end
14
14
 
15
15
  def self.start
16
- sidekiq_config, god_config = get_all_settings
17
-
18
- fail 'No sidekiq instances defined. There is nothing to run.' if sidekiq_config.empty?
16
+ sidekiq_config, god_config = SidekiqConfiguration.get, GodConfiguration.get
19
17
 
20
- abort 'God is running. I found an instance of a running god process. Please stop it manually and try again.' if god_alive?(god_config)
18
+ abort 'God is already running.' if god_alive?(god_config)
21
19
 
22
20
  run(:start, sidekiq_config) do
23
21
  puts 'Starting god.'
@@ -26,37 +24,27 @@ module SidekiqRunner
26
24
  end
27
25
 
28
26
  def self.stop
29
- sidekiq_config, god_config = get_all_settings
27
+ sidekiq_config, god_config = SidekiqConfiguration.get, GodConfiguration.get
30
28
 
31
29
  run(:stop, sidekiq_config) do
32
30
  God::EventHandler.load
33
31
 
34
32
  if god_alive?(god_config)
35
- puts "Stopping process #{god_config.process_name}."
36
-
37
- # Stop all the processes
38
33
  sidekiq_config.each_key do |name|
34
+ puts "Stopping Sidekiq instance #{name}..."
39
35
  God::CLI::Command.new('stop', god_config.options, ['', name])
40
36
  end
41
37
 
42
- puts 'Terminating god.'
38
+ puts "Terminating god process #{god_config.process_name}..."
43
39
  God::CLI::Command.new('terminate', god_config.options, [])
44
40
  else
45
- puts 'God is not running, so no need to stop it.'
41
+ abort 'God is not running, so no need to stop it.'
46
42
  end
47
43
  end
48
44
  end
49
45
 
50
- def self.settings
51
- SidekiqConfiguration.get.to_hash
52
- end
53
-
54
46
  private
55
47
 
56
- def self.get_all_settings
57
- [SidekiqConfiguration.get, GodConfiguration.get]
58
- end
59
-
60
48
  def self.god_alive?(god_config)
61
49
  puts 'Checking whether god is alive...'
62
50
 
@@ -65,7 +53,7 @@ module SidekiqRunner
65
53
  DRb.start_service('druby://127.0.0.1:0')
66
54
  server = DRbObject.new(nil, God::Socket.socket(god_config.port))
67
55
 
68
- # ping server to ensure that it is responsive
56
+ # Ping server to ensure that it is responsive.
69
57
  begin
70
58
  server.ping
71
59
  rescue DRb::DRbConnError
@@ -76,14 +64,15 @@ module SidekiqRunner
76
64
 
77
65
  def self.run(action, sidekiq_config)
78
66
  begin
79
- # Use this flag to actually load all of the god infrastructure
67
+
68
+ # Use this flag to actually load all of the god infrastructure.
80
69
  $load_god = true
81
70
  require 'god'
82
71
  require 'god/cli/run'
83
72
 
84
- # Peform the action
73
+ # Peform the action.
85
74
  yield if block_given?
86
- cb = nil
75
+
87
76
  rescue SystemExit => e
88
77
  cb = e.success? ? "#{action}_success_cb" : "#{action}_error_cb"
89
78
  ensure
@@ -94,5 +83,4 @@ module SidekiqRunner
94
83
  end
95
84
  end
96
85
  end
97
-
98
86
  end
@@ -1,12 +1,18 @@
1
- require 'sidekiq-runner/common_configuration'
1
+ require 'yaml'
2
2
 
3
3
  module SidekiqRunner
4
- class GodConfiguration < CommonConfiguration
4
+ class GodConfiguration
5
5
  def self.default
6
6
  @default ||= GodConfiguration.new
7
7
  end
8
8
 
9
- RUNNER_ATTRIBUTES = [:config_file, :daemonize, :port, :syslog, :events, :options]
9
+ def self.get
10
+ config = default.dup
11
+ config.send :merge_config_file!
12
+ config
13
+ end
14
+
15
+ RUNNER_ATTRIBUTES = [:config_file, :daemonize, :port, :syslog, :events]
10
16
  RUNNER_ATTRIBUTES.each { |att| attr_accessor att }
11
17
 
12
18
  CONFIG_FILE_ATTRIBUTES = [:process_name, :interval, :stop_timeout, :log_file]
@@ -16,24 +22,40 @@ module SidekiqRunner
16
22
  @process_name = 'sidekiq'
17
23
  @interval = 30
18
24
  @stop_timeout = 30
19
- @log_file = File.join(Dir.pwd, 'log', 'god.log')
20
25
 
26
+ @log_file = File.join(Dir.pwd, 'log', 'god.log')
21
27
  @config_file = File.join(Dir.pwd, 'config', 'god.yml')
28
+
22
29
  @daemonize = true
23
- # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock"
24
- # Change this in the configuration file to be able to run multiple instances of god
25
- @port = 17165
26
30
  @syslog = true
27
31
  @events = true
28
- @options = {
32
+
33
+ # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock"
34
+ # Change this in the configuration file to be able to run multiple instances of god.
35
+ @port = 17165
36
+ end
37
+
38
+ def options
39
+ {
29
40
  daemonize: @daemonize,
30
41
  port: @port,
31
42
  syslog: @syslog,
32
43
  events: @events,
33
- config: File.expand_path("../#{@process_name}.god", __FILE__),
44
+ config: File.expand_path("../sidekiq.god", __FILE__),
34
45
  log: @log_file
35
46
  }
36
47
  end
37
48
 
49
+ private
50
+
51
+ def merge_config_file!
52
+ if File.exist?(config_file)
53
+ yml = YAML.load_file(config_file)
54
+ CONFIG_FILE_ATTRIBUTES.each do |k|
55
+ v = yml[k] || yml[k.to_s]
56
+ send("#{k}=", v) unless v.nil?
57
+ end
58
+ end
59
+ end
38
60
  end
39
61
  end
@@ -0,0 +1,76 @@
1
+ $LOAD_PATH.unshift "#{File.expand_path('../..', __FILE__)}"
2
+ require 'sidekiq-runner'
3
+
4
+ sidekiq_config = SidekiqRunner::SidekiqConfiguration.get
5
+ god_config = SidekiqRunner::GodConfiguration.get
6
+
7
+ God.terminate_timeout = god_config.stop_timeout + 10
8
+
9
+ sidekiq_config.each do |name, skiq|
10
+ God.watch do |w|
11
+ w.name = name
12
+
13
+ # Set start command.
14
+ w.start = skiq.build_start_command
15
+
16
+ # Set stop command.
17
+ w.stop = skiq.build_stop_command(god_config.stop_timeout)
18
+ w.stop_timeout = god_config.stop_timeout
19
+
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
+ # Working directory has to be set properly.
25
+ # Be aware that by default, God sets the working directory to / (root dir).
26
+ w.dir = skiq.chdir || Rails.root || Dir.pwd
27
+
28
+ # Determine the state on startup.
29
+ # If process is running move to 'up' state, otherwise move to 'start' state.
30
+ # States transitions: http://godrb.com/
31
+ w.transition(:init, { true => :up, false => :start }) do |on|
32
+ on.condition(:process_running) do |c|
33
+ c.running = true
34
+ c.interval = 5
35
+ end
36
+ end
37
+
38
+ # Determine when process has finished starting.
39
+ # If process is running move to 'up' state.
40
+ w.transition([:start, :restart], :up) do |on|
41
+ on.condition(:process_running) do |c|
42
+ c.running = true
43
+ c.interval = 5
44
+ end
45
+
46
+ # If the process went down during state change, try 5 times, on failure move to 'start' state again.
47
+ on.condition(:tries) do |c|
48
+ c.times = 3
49
+ c.interval = 5
50
+ c.transition = :start
51
+ end
52
+ end
53
+
54
+ # Start if process is not running.
55
+ w.transition(:up, :start) do |on|
56
+ on.condition(:process_running) do |c|
57
+ c.running = false
58
+ # Set poll interval in case kqueue/netlink events won't work (you have to
59
+ # trigger god with root privileges for events to work).
60
+ c.interval = god_config.interval
61
+ end
62
+ end
63
+
64
+ w.lifecycle do |on|
65
+ on.condition(:flapping) do |c|
66
+ c.to_state = [:start, :restart] # If this watch is started or restarted...
67
+ c.times = 5 # 5 times
68
+ c.within = 5.minutes # within 5 minutes
69
+ c.transition = :unmonitored # then unmonitor it.
70
+ c.retry_in = 10.minutes # Then after 10 minutes monitor it again to see if it was just a temporary problem.
71
+ c.retry_times = 5 # If the process is seen to be flapping 5 times
72
+ c.retry_within = 2.hours # within 2 hours, then give up completely.
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,18 +1,21 @@
1
- require 'sidekiq-runner/common_configuration'
2
- require 'fileutils'
1
+ require 'yaml'
3
2
 
4
3
  module SidekiqRunner
5
- class SidekiqConfiguration < CommonConfiguration
4
+ class SidekiqConfiguration
6
5
  include Enumerable
7
6
 
8
- RUNNER_ATTRIBUTES = [:config_file, :daemonize]
7
+ RUNNER_ATTRIBUTES = [:config_file]
9
8
  RUNNER_ATTRIBUTES.each { |att| attr_accessor att }
10
9
 
11
10
  attr_reader :sidekiqs
12
11
 
13
12
  def initialize
14
- @config_file = File.join(Dir.pwd, 'config', 'sidekiq.yml')
15
- @daemonize = true
13
+ @config_file =
14
+ if defined?(Rails)
15
+ File.join(Rails.root, 'config', 'sidekiq.yml')
16
+ else
17
+ File.join(Dir.pwd, 'config', 'sidekiq.yml')
18
+ end
16
19
 
17
20
  @sidekiqs = {}
18
21
  end
@@ -21,6 +24,13 @@ module SidekiqRunner
21
24
  @default ||= SidekiqConfiguration.new
22
25
  end
23
26
 
27
+ def self.get
28
+ config = default.dup
29
+ config.send :merge_config_file!
30
+ config.send :sane?
31
+ config
32
+ end
33
+
24
34
  def each(&block)
25
35
  @sidekiqs.each(&block)
26
36
  end
@@ -33,33 +43,34 @@ module SidekiqRunner
33
43
  @sidekiqs.empty?
34
44
  end
35
45
 
36
- # DELETEME in the future
37
- # Redefined and kept for bakward compatibility
38
- def queue(name, weight = 1)
39
- # Create a default sidekiq instance when no instances were created
40
- fail 'Sidekiq instances hash does not seem to be empty.
41
- It means you are using the newer syntax in the initializer to create at least one instance.
42
- Therefore you should not be using the old queue() function.' unless @sidekiqs.empty?
46
+ def add_instance(name)
47
+ fail "Sidekiq instance with the name '#{name}' already exists! No duplicates please." if @sidekiqs.key?(name)
43
48
 
44
- add_instance('sidekiq_default') do |skiq|
45
- skiq.add_queue('default')
46
- end
49
+ @sidekiqs[name] = SidekiqInstance.new(name)
50
+ yield @sidekiqs[name] if block_given?
47
51
  end
48
52
 
49
- def add_instance(name)
50
- skiq = SidekiqInstance.new(name)
51
- yield skiq if block_given?
52
-
53
- fail "Sidekick instance with the name of #{name} already exists! No duplicates please." if @sidekiqs.has_key?(name)
53
+ # Top-level single instance configuration methods, partially for backward compatibility.
54
54
 
55
- FileUtils.mkdir_p(File.dirname(skiq.pidfile))
56
- FileUtils.mkdir_p(File.dirname(skiq.logfile))
55
+ SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |meth|
56
+ define_method("#{meth}=") do |val|
57
+ ensure_default_sidekiq!
58
+ @sidekiqs.each { |_, skiq| skiq.send("#{meth}=", val) }
59
+ end
60
+ end
57
61
 
58
- @sidekiqs[name] = skiq
62
+ def queue(name, weight = 1)
63
+ fail 'Multiple Sidekiq instances defined and queue() outside of instance block called.' if @sidekiqs.size > 1
59
64
 
60
- skiq
65
+ ensure_default_sidekiq!
66
+ @sidekiqs.values.first.add_queue(name, weight)
61
67
  end
62
68
 
69
+ alias_method :add_queue, :queue
70
+ alias_method :configfile=, :config_file=
71
+
72
+ # Callbacks.
73
+
63
74
  %w(start stop).each do |action|
64
75
  %w(success error).each do |state|
65
76
  attr_reader "#{action}_#{state}_cb".to_sym
@@ -72,44 +83,25 @@ module SidekiqRunner
72
83
 
73
84
  private
74
85
 
86
+ def ensure_default_sidekiq!
87
+ add_instance('sidekiq_default') if empty?
88
+ end
89
+
75
90
  def merge_config_file!
76
91
  sidekiqs_common_config = {}
77
- yml = {}
78
-
79
- if File.exist?(config_file)
80
- yml = YAML.load_file(config_file)
81
- # Get sidekiq config common for all instances
82
- SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
83
- v = yml[k] || yml[k.to_s]
84
- sidekiqs_common_config[k] = v if v
85
- end
86
- end
87
92
 
88
- # Backwards compatibility
89
- # Get sidekiq pidfile and logfile if no sidekiq instance was specified
90
- SidekiqInstance::INDIVIDUAL_FILE_ATTRIBUTES.each do |k|
91
- v = yml[k] || yml[k.to_s]
92
- sidekiqs_common_config[k] = v if v
93
- end
93
+ yml = File.exist?(config_file) ? YAML.load_file(config_file) : {}
94
+ yml = Hash[yml.map { |k, v| [k.to_sym, v] }]
94
95
 
95
- @sidekiqs.each do |name, skiq|
96
- # Symbolize keys in yml hash
97
- if yml[name] && yml[name].is_a?(Hash)
98
- yml_config = Hash[yml[name].map { |k, v| [k.to_sym, v] }]
99
- end
100
- # Merge common and specific sidekiq instance configs
101
- # Sidekiq instances not defined in the initializer but present in yml will be ignored
102
- final_skiq_config = yml_config ? sidekiqs_common_config.merge(yml_config) : sidekiqs_common_config
103
- skiq.merge_config!(final_skiq_config)
104
- skiq.sane?
105
- end
106
-
107
- self
96
+ @sidekiqs.each_value { |skiq| skiq.merge_config_file!(yml) }
108
97
  end
109
98
 
110
99
  def sane?
111
- fail 'No requirefile given and not in Rails env.' if !defined?(Rails) && !requirefile
112
100
  fail 'No sidekiq instances defined. Nothing to run.' if @sidekiqs.empty?
101
+ fail 'Sidekiq instances with the same pidfile found.' if @sidekiqs.values.map(&:pidfile).uniq.size < @sidekiqs.size
102
+ fail 'Sidekiq instances with the same logfile found.' if @sidekiqs.values.map(&:logfile).uniq.size < @sidekiqs.size
103
+
104
+ @sidekiqs.each_value { |skiq| skiq.sane? }
113
105
  end
114
106
  end
115
107
  end
@@ -1,9 +1,8 @@
1
1
  module SidekiqRunner
2
2
  class SidekiqInstance
3
3
 
4
- CONFIG_FILE_ATTRIBUTES = [:bundle_env, :chdir, :requirefile, :concurrency, :verbose]
5
- INDIVIDUAL_FILE_ATTRIBUTES = [:pidfile, :logfile]
6
- CONFIG_FILE_ATTRIBUTES.concat(INDIVIDUAL_FILE_ATTRIBUTES).each { |att| attr_accessor att }
4
+ CONFIG_FILE_ATTRIBUTES = [:bundle_env, :chdir, :requirefile, :concurrency, :verbose, :pidfile, :logfile]
5
+ CONFIG_FILE_ATTRIBUTES.each { |att| attr_accessor att }
7
6
 
8
7
  attr_reader :name, :queues
9
8
 
@@ -14,35 +13,68 @@ module SidekiqRunner
14
13
  @queues = []
15
14
 
16
15
  @bundle_env = true
17
- @daemonize = true
18
16
  @chdir = nil
19
17
  @requirefile = nil
20
18
  @pidfile = File.join(Dir.pwd, 'tmp', 'pids', "#{@name}.pid")
21
19
  @logfile = File.join(Dir.pwd, 'log', "#{@name}.log")
22
20
  @concurrency = 4
23
21
  @verbose = false
24
-
25
22
  end
26
23
 
27
24
  def add_queue(queue_name, weight = 1)
28
25
  fail "Cannot add the queue. The name is empty!" if queue_name.empty?
29
26
  fail "Cannot add the queue. The weight is not an integer!" unless weight.is_a? Integer
30
- fail "Cannot add the queue. The queue with \"#{queue_name}\" name already exist" if @queues.any?{|arr| arr.first == queue_name}
27
+ fail "Cannot add the queue. The queue with \"#{queue_name}\" name already exist" if @queues.any? { |q| q.first == queue_name }
31
28
  @queues << [queue_name, weight]
32
29
  end
33
30
 
31
+ def merge_config_file!(yml)
32
+ # Get global configuration options.
33
+ SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
34
+ send("#{k}=", yml[k]) unless yml[k].nil?
35
+ end
36
+
37
+ # Override with instance-specific options.
38
+ if (syml = yml[@name.to_sym]) && (syml.is_a?(Hash))
39
+ syml = Hash[syml.map { |k, v| [k.to_sym, v] }]
40
+
41
+ SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
42
+ send("#{k}=", syml[k]) unless syml[k].nil?
43
+ end
44
+ end
45
+ end
46
+
34
47
  def sane?
35
48
  fail "No queues given for #{@name}!" if @queues.empty?
49
+ fail "No requirefile given for #{@name} and not in Rails environment!" if !defined?(Rails) && !requirefile
36
50
  end
37
51
 
38
- def merge_config!(skiq)
39
- CONFIG_FILE_ATTRIBUTES.each do |k|
40
- v = nil || skiq[k]
41
- send("#{k}=", v) unless v.nil?
42
- end
52
+ def build_start_command
53
+ cmd = []
54
+ cmd << (bundle_env ? 'bundle exec sidekiq' : 'sidekiq')
55
+ cmd << '-d'
56
+ cmd << "-c #{concurrency}"
57
+ cmd << '-v' if verbose
58
+ cmd << "-L #{logfile}"
59
+ cmd << "-P #{pidfile}"
60
+ cmd << "-e #{Rails.env}" if defined?(Rails)
61
+ cmd << "-r #{requirefile}" if requirefile
62
+
63
+ queues.each do |q, w|
64
+ cmd << "-q #{q},#{w.to_s}"
65
+ end
43
66
 
44
- self
67
+ cmd.join(' ')
45
68
  end
46
69
 
70
+ def build_stop_command(timeout)
71
+ cmd = []
72
+ cmd << (bundle_env ? 'bundle exec sidekiqctl' : 'sidekiqctl')
73
+ cmd << 'stop'
74
+ cmd << pidfile
75
+ cmd << timeout
76
+
77
+ cmd.join(' ')
78
+ end
47
79
  end
48
- end
80
+ end
@@ -3,18 +3,18 @@ require 'sidekiq-runner'
3
3
  rails_env = Rake::Task.task_defined?(:environment) ? [:environment] : []
4
4
 
5
5
  namespace :sidekiqrunner do
6
- desc 'Start sidekiq-runner instances'
6
+ desc 'Start Sidekiq instances'
7
7
  task start: rails_env do
8
8
  puts 'Starting sidekiq instances...'
9
9
  SidekiqRunner.start
10
10
  end
11
11
 
12
- desc 'Stop sidekiq-runner instances'
12
+ desc 'Stop Sidekiq instances'
13
13
  task stop: rails_env do
14
14
  puts 'Gracefully shutting down sidekiq instances...'
15
15
  SidekiqRunner.stop
16
16
  end
17
17
 
18
- desc 'Restart sidekiq-runner instances'
19
- task restart: ['sidekiq:stop', 'sidekiq:start']
18
+ desc 'Restart Sidekiq instances'
19
+ task restart: ['sidekiqrunner:stop', 'sidekiqrunner:start']
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqRunner
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - FlavourSys Technology GmbH
@@ -38,22 +38,21 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.13'
41
- description: A little collection of Sidekiq start/stop rake tasks and configuration
42
- framework
41
+ description: Provide an easy way to configure, start, and monitor all your Sidekiq
42
+ processes
43
43
  email: technology@flavoursys.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - lib/sidekiq-runner.rb
49
- - lib/sidekiq-runner/common_configuration.rb
50
49
  - lib/sidekiq-runner/god_configuration.rb
51
- - lib/sidekiq-runner/sidekiq_command_builder.rb
50
+ - lib/sidekiq-runner/sidekiq.god
52
51
  - lib/sidekiq-runner/sidekiq_configuration.rb
53
52
  - lib/sidekiq-runner/sidekiq_instance.rb
54
53
  - lib/sidekiq-runner/tasks.rb
55
54
  - lib/sidekiq-runner/version.rb
56
- homepage: http://flavoursys.com
55
+ homepage: https://github.com/FlavourSys/sidekiq-runner
57
56
  licenses:
58
57
  - MIT
59
58
  metadata: {}
@@ -76,5 +75,5 @@ rubyforge_project:
76
75
  rubygems_version: 2.2.2
77
76
  signing_key:
78
77
  specification_version: 4
79
- summary: Sidekiq rake task collection
78
+ summary: Sidekiq configuration and rake tasks
80
79
  test_files: []
@@ -1,46 +0,0 @@
1
- require 'yaml'
2
-
3
- module SidekiqRunner
4
-
5
- # common functions for GodConfiguration and Configuration classes
6
- class CommonConfiguration
7
- # this method MUST be reimplemented
8
- def self.default
9
- fail(NotImplementedError, "Method \"#{__method__}\" is not implemented in \"#{name}\" class. Please DO implement this method to be able to derive from CommonConfiguration class.")
10
- end
11
-
12
- RUNNER_ATTRIBUTES = []
13
- CONFIG_FILE_ATTRIBUTES = []
14
-
15
- @config_file = ''
16
-
17
- def to_hash
18
- Hash[CONFIG_FILE_ATTRIBUTES.map { |att| [att, send(att)] }]
19
- end
20
-
21
- def self.get
22
- config = default.dup
23
- config.send :merge_config_file!
24
- config.send :sane?
25
- config
26
- end
27
-
28
- private
29
-
30
- def merge_config_file!
31
- if File.exist?(config_file)
32
- yml = YAML.load_file(config_file)
33
- CONFIG_FILE_ATTRIBUTES.each do |k|
34
- v = yml[k] || yml[k.to_s]
35
- send("#{k}=", v) unless v.nil?
36
- end
37
- end
38
-
39
- self
40
- end
41
-
42
- def sane?
43
- end
44
-
45
- end # class
46
- end # module
@@ -1,31 +0,0 @@
1
- module SidekiqCommandBuilder
2
-
3
- def self.build_start_command(sidekiq_config, skiq)
4
- cmd = []
5
- cmd << (skiq.bundle_env ? 'bundle exec sidekiq' : 'sidekiq')
6
- cmd << '-d' if sidekiq_config.daemonize
7
- cmd << "-c #{skiq.concurrency}"
8
- cmd << "-e #{Rails.env}" if defined?(Rails)
9
- cmd << '-v' if skiq.verbose
10
- cmd << "-L #{skiq.logfile}"
11
- cmd << "-P #{skiq.pidfile}"
12
- cmd << "-r #{skiq.requirefile}" if skiq.requirefile
13
-
14
- skiq.queues.each do |q, w|
15
- cmd << "-q #{q},#{w.to_s}"
16
- end
17
-
18
- cmd.join(' ')
19
- end
20
-
21
- def self.build_stop_command(skiq, timeout)
22
- cmd = []
23
- cmd << (skiq.bundle_env ? 'bundle exec sidekiqctl' : 'sidekiqctl')
24
- cmd << 'stop'
25
- cmd << skiq.pidfile
26
- cmd << timeout
27
-
28
- cmd.join(' ')
29
- end
30
-
31
- end