Module: SidekiqRunner

Defined in:
lib/sidekiq-runner.rb,
lib/sidekiq-runner/version.rb,
lib/sidekiq-runner/sidekiq_instance.rb,
lib/sidekiq-runner/god_configuration.rb,
lib/sidekiq-runner/sidekiq_configuration.rb

Defined Under Namespace

Classes: GodConfiguration, SidekiqConfiguration, SidekiqInstance

Constant Summary collapse

VERSION =
'0.2.3'

Class Method Summary collapse

Class Method Details

.configure {|SidekiqConfiguration.default| ... } ⇒ Object

Yields:



7
8
9
# File 'lib/sidekiq-runner.rb', line 7

def self.configure
  yield SidekiqConfiguration.default if block_given?
end

.configure_god {|GodConfiguration.default| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/sidekiq-runner.rb', line 11

def self.configure_god
  yield GodConfiguration.default if block_given?
end

.restart(sidekiq_instances: []) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidekiq-runner.rb', line 51

def self.restart(sidekiq_instances: [])
  sidekiq_config = SidekiqConfiguration.get
  god_config = GodConfiguration.get

  return unless god_alive?(god_config)

  run(:restart, sidekiq_config, god_config) do
    sidekiq_config.each_key do |name|
      God::CLI::Command.new('restart', god_config.options, ['', name]) if sidekiq_instances.empty? || sidekiq_instances.include?(name.to_sym)
    end
  end
end

.running?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/sidekiq-runner.rb', line 64

def self.running?
  god_alive? GodConfiguration.get
end

.startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sidekiq-runner.rb', line 15

def self.start
  sidekiq_config, god_config = SidekiqConfiguration.get, GodConfiguration.get

  abort 'God is already running.' if god_alive?(god_config)

  run(:start, sidekiq_config, god_config) do
    $0 = "SidekiqRunner/God (#{god_config.process_name})"

    puts 'Starting god.'
    God::CLI::Run.new(god_config.options)
  end

  sleep 5
  fail 'Failed to start God.' unless god_alive?(god_config)
end

.stopObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sidekiq-runner.rb', line 31

def self.stop
  sidekiq_config, god_config = SidekiqConfiguration.get, GodConfiguration.get

  run(:stop, sidekiq_config, god_config) do
    God::EventHandler.load

    if god_alive?(god_config)
      puts "Terminating god process #{god_config.process_name}..."

      sidekiq_config.each_key do |name|
        God::CLI::Command.new('stop', god_config.options, ['', name])
      end

      God::CLI::Command.new('terminate', god_config.options, [])
    else
      abort 'God is not running, so no need to stop it.'
    end
  end
end