Class: SidekiqRunner::GodConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq-runner/god_configuration.rb

Constant Summary collapse

RUNNER_ATTRIBUTES =
[:config_file, :daemonize, :port, :syslog, :events]
CONFIG_FILE_ATTRIBUTES =
[:process_name, :interval, :stop_timeout, :log_file, :log_level, :maximum_memory_usage, :pid]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGodConfiguration

Returns a new instance of GodConfiguration.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sidekiq-runner/god_configuration.rb', line 23

def initialize
  @process_name = 'sidekiq'
  @interval  = 30
  @stop_timeout = 30
  @maximum_memory_usage = nil

  @log_file   = File.join(Dir.pwd, 'log', 'god.log')
  @config_file  = File.join(Dir.pwd, 'config', 'god.yml')

  @daemonize = true
  @syslog = true
  @events = true
  @pid = nil
  @log_level = :warn

  # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock" and the pidfile name
  # Change this in the configuration file to be able to run multiple instances of god.
  @port = 17165

  @generic_watchers = []
end

Instance Attribute Details

#generic_watchersObject (readonly)

Returns the value of attribute generic_watchers.



21
22
23
# File 'lib/sidekiq-runner/god_configuration.rb', line 21

def generic_watchers
  @generic_watchers
end

Class Method Details

.defaultObject



5
6
7
# File 'lib/sidekiq-runner/god_configuration.rb', line 5

def self.default
  @default ||= GodConfiguration.new
end

.getObject



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

def self.get
  config = default.dup
  config.merge_config_file!
  config
end

Instance Method Details

#add_generic(&blk) ⇒ Object



45
46
47
# File 'lib/sidekiq-runner/god_configuration.rb', line 45

def add_generic(&blk)
  @generic_watchers << blk
end

#create_directories!Object



74
75
76
# File 'lib/sidekiq-runner/god_configuration.rb', line 74

def create_directories!
  FileUtils.mkdir_p(File.dirname(log_file)) if log_file
end

#merge_config_file!Object



64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq-runner/god_configuration.rb', line 64

def merge_config_file!
  if File.exist?(config_file)
    yml = YAML.load_file(config_file)
    CONFIG_FILE_ATTRIBUTES.each do |k|
      v = yml[k] || yml[k.to_s]
      send("#{k}=", v) unless v.nil?
    end
  end
end

#optionsObject



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

def options
  create_directories!

  {
    daemonize: @daemonize,
    port: @port,
    syslog: @syslog,
    events: @events,
    config: File.expand_path("../sidekiq.god", __FILE__),
    log: @log_file,
    pid: @pid,
    log_level: @log_level
  }
end