sidekiq-runner 0.1.1 → 0.1.7

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
- SHA1:
3
- metadata.gz: 4b7fa70811b720ebc2ab7a34f674df39ce1f2816
4
- data.tar.gz: 61bbd1e7ba1e5b094f0b0b4dd3b9b8f2cef8cde9
2
+ SHA256:
3
+ metadata.gz: accd017e5f1993d88519d7a5b8652765723b0040cf58807f84ddfe313ac250c6
4
+ data.tar.gz: 4b94a7588b6faaeb817c95322a0073cebbbf3876f1bbf75a41132296a592c923
5
5
  SHA512:
6
- metadata.gz: 1e15d46d709d85d15832e1595a0601ffc77c7cc60b71dda140a5d92fa9d2644252c46f84e04e594f9880799f6680a9c0b68b00ba5455c5370479eaa6de1a6f7d
7
- data.tar.gz: 9728647c72592024dba383849ded7f4ed3dc658ceb28cb09b944a7926f9314d0518422441b06a12e7dcb3690b009ec2363b546bb6ec746bf5d5c1edbaa29e211
6
+ metadata.gz: b114badfa21c9f2a25600e7aa5966e963c84238a4da58ce909928695a496f6ea8778e11969ebc12de5223ddc69543831f9f05e26d8592d6d6340f653c3798b31
7
+ data.tar.gz: d848fbdbb4880b0068f5347abd3367cb72f5438a4529c47e0d03b74be8ae3d8acc11f41f5790d7af5ffa6c91b430f1ba46e679e37ad9c15c5c2e56936ed50a84
@@ -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,13 +15,14 @@ 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]
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
22
22
  @process_name = 'sidekiq'
23
23
  @interval = 30
24
24
  @stop_timeout = 30
25
+ @maximum_memory_usage = nil
25
26
 
26
27
  @log_file = File.join(Dir.pwd, 'log', 'god.log')
27
28
  @config_file = File.join(Dir.pwd, 'config', 'god.yml')
@@ -29,8 +30,10 @@ module SidekiqRunner
29
30
  @daemonize = true
30
31
  @syslog = true
31
32
  @events = true
33
+ @pid = nil
34
+ @log_level = :warn
32
35
 
33
- # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock"
36
+ # This is going to be a part of the .sock file name e.g. "/tmp/god.17165.sock" and the pidfile name
34
37
  # Change this in the configuration file to be able to run multiple instances of god.
35
38
  @port = 17165
36
39
  end
@@ -44,7 +47,9 @@ module SidekiqRunner
44
47
  syslog: @syslog,
45
48
  events: @events,
46
49
  config: File.expand_path("../sidekiq.god", __FILE__),
47
- log: @log_file
50
+ log: @log_file,
51
+ pid: @pid,
52
+ log_level: @log_level
48
53
  }
49
54
  end
50
55
 
@@ -61,5 +66,13 @@ module SidekiqRunner
61
66
  def create_directories!
62
67
  FileUtils.mkdir_p(File.dirname(log_file))
63
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
64
77
  end
65
78
  end
@@ -21,6 +21,10 @@ sidekiq_config.each do |name, skiq|
21
21
  w.pid_file = skiq.pidfile
22
22
  w.behavior(:clean_pid_file)
23
23
 
24
+ # Set uid/gid if requested.
25
+ w.uid = skiq.uid if skiq.uid
26
+ w.gid = skiq.gid if skiq.gid
27
+
24
28
  # Working directory has to be set properly.
25
29
  # Be aware that by default, God sets the working directory to / (root dir).
26
30
  w.dir = skiq.chdir || (defined?(Rails) ? Rails.root : Dir.pwd)
@@ -61,6 +65,21 @@ sidekiq_config.each do |name, skiq|
61
65
  end
62
66
  end
63
67
 
68
+ # Monitor process memory usage.
69
+ if god_config.maximum_memory_usage
70
+ w.restart_if do |restart|
71
+ restart.condition(:memory_usage) do |c|
72
+ c.above = god_config.maximum_memory_usage.to_i.megabytes
73
+ c.times = 3
74
+ c.interval = god_config.interval
75
+ end
76
+ end
77
+ end
78
+
79
+ if skiq.config_blocks.length > 0
80
+ skiq.config_blocks.each { |blk| blk.call(w) }
81
+ end
82
+
64
83
  w.lifecycle do |on|
65
84
  on.condition(:flapping) do |c|
66
85
  c.to_state = [:start, :restart] # If this watch is started or restarted...
@@ -4,10 +4,10 @@ module SidekiqRunner
4
4
  RUNNER_ATTRIBUTES = [:bundle_env, :chdir, :requirefile]
5
5
  RUNNER_ATTRIBUTES.each { |att| attr_accessor att }
6
6
 
7
- CONFIG_FILE_ATTRIBUTES = [:concurrency, :verbose, :pidfile, :logfile, :tag]
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?
@@ -23,6 +23,10 @@ module SidekiqRunner
23
23
  @concurrency = 4
24
24
  @verbose = false
25
25
  @tag = name
26
+ @rbtrace = false
27
+ @uid = nil
28
+ @gid = nil
29
+ @config_blocks = []
26
30
  end
27
31
 
28
32
  def add_queue(queue_name, weight = 1)
@@ -32,6 +36,10 @@ module SidekiqRunner
32
36
  @queues << [queue_name, weight]
33
37
  end
34
38
 
39
+ def god_config(&block)
40
+ @config_blocks << block
41
+ end
42
+
35
43
  def merge_config_file!(yml)
36
44
  # Get global configuration options.
37
45
  SidekiqInstance::CONFIG_FILE_ATTRIBUTES.each do |k|
@@ -57,7 +65,8 @@ module SidekiqRunner
57
65
  create_directories!
58
66
 
59
67
  cmd = []
60
- cmd << (bundle_env ? 'bundle exec sidekiq' : 'sidekiq')
68
+ cmd << 'bundle exec' if bundle_env
69
+ cmd << (rbtrace ? File.expand_path('../../../script/sidekiq_rbtrace', __FILE__) : 'sidekiq')
61
70
  cmd << '-d'
62
71
  cmd << "-c #{concurrency}"
63
72
  cmd << '-v' if verbose
@@ -1,3 +1,3 @@
1
1
  module SidekiqRunner
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbtrace'
4
+
5
+ def sidekiq_bin
6
+ require 'sidekiq/cli'
7
+
8
+ begin
9
+ cli = Sidekiq::CLI.instance
10
+ cli.parse
11
+ cli.run
12
+ rescue => e
13
+ raise e if $DEBUG
14
+ STDERR.puts e.message
15
+ STDERR.puts e.backtrace.join("\n")
16
+ exit 1
17
+ end
18
+ end
19
+
20
+ sidekiq = `which sidekiq` rescue ''
21
+ if sidekiq.empty?
22
+ # When we can't locate the Sidekiq executable, mimick
23
+ # its behaviour here.
24
+ sidekiq_bin
25
+ else
26
+ begin
27
+ # Otherwise load the sidekiq executable.
28
+ load sidekiq.strip
29
+ rescue
30
+ sidekiq_bin
31
+ end
32
+ 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.1
4
+ version: 0.1.7
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: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2021-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.3'
19
+ version: '11'
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: '10.3'
26
+ version: '11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: god
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,7 @@ files:
52
52
  - lib/sidekiq-runner/sidekiq_instance.rb
53
53
  - lib/sidekiq-runner/tasks.rb
54
54
  - lib/sidekiq-runner/version.rb
55
+ - script/sidekiq_rbtrace
55
56
  homepage: https://github.com/FlavourSys/sidekiq-runner
56
57
  licenses:
57
58
  - MIT
@@ -71,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  - !ruby/object:Gem::Version
72
73
  version: '0'
73
74
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.2.2
75
+ rubygems_version: 3.2.16
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Sidekiq configuration and rake tasks