sidekiq-runner 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40e3ccfb608ce10065ae202f0c2115beb6d12731
4
- data.tar.gz: 666ab8b6d2581309f11c082848bbb24e5e2ec1f8
3
+ metadata.gz: 65f6d473c59401d2c4206a1f1a5a91ac53baa55c
4
+ data.tar.gz: 5d56060902cd554d9928969e995d42df9ae55803
5
5
  SHA512:
6
- metadata.gz: 070bba932a4942753c19bf5e585da2f600bae70d89d757dd5989a8e7ac71cb13f30b91d02773f0128b733e225d75747e53e4f7b41f2f03e5fc3fc7e950d9501a
7
- data.tar.gz: 992af79e5d6b807afeaef9382b68fb6a7376e43d85dbf73636373318ff0358ce01225267e69700dc1dc306aba284a43fa46968305bdea2be717d77060ce9ba5b
6
+ metadata.gz: 0c541c8fde7042c286e4c872c218f003c05b8c68e0b31272e653e47a256d62b647add742bd2448cbce71b2685d778de6275ba995e96c43ac6c6afcdfc29eabb9
7
+ data.tar.gz: 81cf308cec2a49fdf3aa855595bb14220f98de69ecd574f3b713adbc9a4dc283826984b3f9710af8a14e004c82fc4de928de076c262c53e13d7c2a5da6541689
@@ -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)
@@ -69,7 +69,7 @@ module SidekiqRunner
69
69
  true
70
70
  end
71
71
 
72
- def self.run(action, sidekiq_config)
72
+ def self.run(action, sidekiq_config, god_config)
73
73
  begin
74
74
 
75
75
  # Use this flag to actually load all of the god infrastructure.
@@ -77,6 +77,11 @@ module SidekiqRunner
77
77
  require 'god'
78
78
  require 'god/cli/run'
79
79
 
80
+ if [:start, :stop].include? action
81
+ cb = god_config.send("before_#{action}_cb".to_sym)
82
+ cb.call if cb
83
+ end
84
+
80
85
  # Peform the action.
81
86
  yield if block_given?
82
87
 
@@ -15,7 +15,7 @@ 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
21
  def initialize
@@ -31,6 +31,7 @@ module SidekiqRunner
31
31
  @syslog = true
32
32
  @events = true
33
33
  @pid = nil
34
+ @log_level = :warn
34
35
 
35
36
  # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock" and the pidfile name
36
37
  # Change this in the configuration file to be able to run multiple instances of god.
@@ -47,7 +48,8 @@ module SidekiqRunner
47
48
  events: @events,
48
49
  config: File.expand_path("../sidekiq.god", __FILE__),
49
50
  log: @log_file,
50
- pid: @pid
51
+ pid: @pid,
52
+ log_level: @log_level
51
53
  }
52
54
  end
53
55
 
@@ -64,5 +66,13 @@ module SidekiqRunner
64
66
  def create_directories!
65
67
  FileUtils.mkdir_p(File.dirname(log_file))
66
68
  end
69
+
70
+ %w(start stop).each do |action|
71
+ attr_reader "before_#{action}_cb".to_sym
72
+
73
+ define_method("before_#{action}") do |&block|
74
+ instance_variable_set("@before_#{action}_cb".to_sym, block)
75
+ end
76
+ end
67
77
  end
68
78
  end
@@ -76,6 +76,10 @@ sidekiq_config.each do |name, skiq|
76
76
  end
77
77
  end
78
78
 
79
+ if skiq.config_blocks.length > 0
80
+ skiq.config_blocks.each { |blk| blk.call(w) }
81
+ end
82
+
79
83
  w.lifecycle do |on|
80
84
  on.condition(:flapping) do |c|
81
85
  c.to_state = [:start, :restart] # If this watch is started or restarted...
@@ -7,7 +7,7 @@ module SidekiqRunner
7
7
  CONFIG_FILE_ATTRIBUTES = [:concurrency, :verbose, :pidfile, :logfile, :tag, :rbtrace, :uid, :gid]
8
8
  CONFIG_FILE_ATTRIBUTES.each { |att| attr_accessor att }
9
9
 
10
- attr_reader :name, :queues
10
+ attr_reader :name, :queues, :config_blocks
11
11
 
12
12
  def initialize(name)
13
13
  fail "No sidekiq instance name given!" if name.empty?
@@ -26,6 +26,7 @@ module SidekiqRunner
26
26
  @rbtrace = false
27
27
  @uid = nil
28
28
  @gid = nil
29
+ @config_blocks = []
29
30
  end
30
31
 
31
32
  def add_queue(queue_name, weight = 1)
@@ -35,6 +36,10 @@ module SidekiqRunner
35
36
  @queues << [queue_name, weight]
36
37
  end
37
38
 
39
+ def god_config(&block)
40
+ @config_blocks << block
41
+ end
42
+
38
43
  def merge_config_file!(yml)
39
44
  # Get global configuration options.
40
45
  SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
@@ -1,3 +1,3 @@
1
1
  module SidekiqRunner
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
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.1.5
4
+ version: 0.1.6
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: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.4.5
76
+ rubygems_version: 2.5.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Sidekiq configuration and rake tasks