sidekiq-bossman 0.0.3

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p374@sidekiq-bossman"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.18.5 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq-bossman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2013 Nick Zalabak
2
+
3
+ sidekiq-bossman is an Open Source project licensed under the terms of
4
+ the LGPLv3 license (same as sidekiq). Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
5
+ for license text.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Sidekiq::Bossman
2
+
3
+ The goal of Sidekiq::Bossman is to provide an easy programmatic approach
4
+ to starting and stopping Sidekiq workers. Everything in Sidekiq::Bossman
5
+ is nothing more than an idiomatic Ruby abstraction atop what already exists in Sidekiq.
6
+ I was compelled to write this abstraction because I have many projects that
7
+ have the following commands scattered about in Rake tasks, shell scripts, etc:
8
+
9
+ system "nohup bundle exec sidekiq -e #{Rails.env} -C #{Rails.root}/config/sidekiq.yml -P #{Rails.root}/tmp/pids/sidekiq.pid >> #{Rails.root}/log/sidekiq.log 2>&1 &"
10
+ system "if [ -f tmp/pids/sidekiq.pid ]; then bundle exec sidekiqctl stop tmp/pids/sidekiq.pid; fi"
11
+
12
+ While there is nothing wrong with these commands, it felt error prone and sloppy to be
13
+ copying and pasting this across new projects. Since it has become a pattern with some of my projects I find
14
+ it useful.
15
+
16
+ Thanks to Mike Perham for providing us such a great framework.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'sidekiq-bossman'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install sidekiq-bossman
31
+
32
+ ## Usage
33
+
34
+ Start your Sidekiq workers
35
+
36
+ Sidekiq::Bossman.new(Rails.root.to_s).start_workers
37
+
38
+ Stop your Sidekiq workers
39
+
40
+ Sidekiq::Bossman.new(Rails.root.to_s).stop_workers
41
+
42
+ When initializing Sidekiq::Bossman it can take an options Hash, these are the defaults:
43
+
44
+ {:config => "#{project_root}/config/sidekiq.yml",
45
+ :pidfile => "#{project_root}/tmp/pids/sidekiq.pid",
46
+ :logfile => "#{project_root}/log/sidekiq.log",
47
+ :require => "#{project_root}",
48
+ :timeout => 10,
49
+ :verbose => false,
50
+ :queue => nil,
51
+ :concurrency => nil,
52
+ :daemon => true}
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run Rspecs"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ class Bossman
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'sidekiq/cli'
3
+
4
+ module Sidekiq
5
+ class Bossman
6
+
7
+ attr_accessor :config, :pidfile,
8
+ :logfile, :require,
9
+ :daemon, :timeout,
10
+ :verbose, :concurrency,
11
+ :queue, :environment
12
+
13
+
14
+ ##
15
+ # Takes the following options that currently match the version
16
+ # of Sidekiq this gem depends upon:
17
+ # :config, :pidfile, :logfile, :require, :timeout, :verbose, :queue,
18
+ # :concurrency, :daemon
19
+ def initialize(project_root, options = {})
20
+
21
+ default_options = {:config => "#{project_root}/config/sidekiq.yml",
22
+ :pidfile => "#{project_root}/tmp/pids/sidekiq.pid",
23
+ :logfile => "#{project_root}/log/sidekiq.log",
24
+ :require => "#{project_root}",
25
+ :environment => "development",
26
+ :timeout => 10,
27
+ :verbose => false,
28
+ :queue => nil,
29
+ :concurrency => nil,
30
+ :daemon => true}
31
+ options = default_options.merge(options)
32
+ options.each { |k, v| send("#{k}=", v) }
33
+ end
34
+
35
+ def start_workers
36
+ sidekiq = Sidekiq::CLI.instance
37
+
38
+ args = []
39
+
40
+ ["-r", @require].each { |arg| args << arg } unless @require.nil?
41
+ ["-t", @timeout.to_s].each { |arg| args << arg } unless @timeout.nil?
42
+ ["-L", @logfile].each { |arg| args << arg } unless @logfile.nil?
43
+ ["-C", @config].each { |arg| args << arg } unless @config.nil?
44
+ ["-P", @pidfile].each { |arg| args << arg } unless @pidfile.nil?
45
+ ["-q", @queue].each { |arg| args << arg } unless @queue.nil?
46
+ ["-c", @concurrency].each { |arg| args << arg } unless @concurrency.nil?
47
+ ["-e", @environment].each { |arg| args << arg } unless @environment.nil?
48
+ args << "-d" if @daemon == true
49
+ args << "-v" if @verbose == true
50
+
51
+ sidekiq.parse args
52
+
53
+ sidekiq.run
54
+ end
55
+
56
+ def stop_workers
57
+ system "if [ -f #{@pidfile} ]; then bundle exec sidekiqctl stop #{@pidfile}; fi"
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq-bossman/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sidekiq-bossman"
8
+ gem.version = Sidekiq::Bossman::VERSION
9
+ gem.authors = ["Nick Zalabak"]
10
+ gem.email = ["techwhizbang@gmail.com"]
11
+ gem.description = %q{A Sidekiq utility that takes a programmatic approach to starting|stopping Sidekiq workers}
12
+ gem.summary = %q{Start|stop your Sidekiq workers with ease}
13
+ gem.homepage = "https://github.com/techwhizbang/sidekiq-bossman"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency(%q<sidekiq>, ["~> 2.7.1"])
20
+ gem.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
21
+ gem.add_development_dependency(%q<rake>, ["~> 10.0.3"])
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/sidekiq-bossman")
3
+
4
+ describe Sidekiq::Bossman do
5
+
6
+ before do
7
+ @sidekiq_bossman = Sidekiq::Bossman.new(File.expand_path(File.dirname(__FILE__) + "/sidekiq_project"),
8
+ :require => "#{File.expand_path(File.dirname(__FILE__) + "/sidekiq_project")}/boot.rb",
9
+ :environment => "test",
10
+ :daemon => true)
11
+ end
12
+
13
+ after do
14
+ begin
15
+ Process.kill("TERM", File.read(@sidekiq_bossman.pidfile).to_i)
16
+ rescue
17
+ end
18
+ end
19
+
20
+ context ".start" do
21
+
22
+ it 'successfully starts the Sidekiq workers' do
23
+ begin
24
+ fork { @sidekiq_bossman.start_workers }
25
+ sleep 2
26
+ ensure
27
+ File.exists?(@sidekiq_bossman.pidfile).should be_true
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ context ".stop" do
34
+
35
+ it 'successfully stops the Sidekiq workers' do
36
+ begin
37
+ fork { @sidekiq_bossman.start_workers }
38
+ sleep 2
39
+ @sidekiq_bossman.stop_workers
40
+ ensure
41
+ File.exists?(@sidekiq_bossman.pidfile).should be_false
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'sidekiq'
@@ -0,0 +1,6 @@
1
+ ---
2
+ :verbose: false
3
+ :concurrency: 7
4
+ :queues:
5
+ - [q1, 1]
6
+ - [q2, 1]
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-bossman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Zalabak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.7.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.0.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.3
62
+ description: A Sidekiq utility that takes a programmatic approach to starting|stopping
63
+ Sidekiq workers
64
+ email:
65
+ - techwhizbang@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rvmrc
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/sidekiq-bossman.rb
77
+ - lib/sidekiq-bossman/version.rb
78
+ - sidekiq-bossman.gemspec
79
+ - spec/sidekiq_bossman_spec.rb
80
+ - spec/sidekiq_project/boot.rb
81
+ - spec/sidekiq_project/config/sidekiq.yml
82
+ homepage: https://github.com/techwhizbang/sidekiq-bossman
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 1911942347009138160
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 1911942347009138160
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.25
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Start|stop your Sidekiq workers with ease
112
+ test_files:
113
+ - spec/sidekiq_bossman_spec.rb
114
+ - spec/sidekiq_project/boot.rb
115
+ - spec/sidekiq_project/config/sidekiq.yml