guard-sidekiq 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/README.markdown +90 -0
- data/Rakefile +6 -0
- data/guard-sidekiq.gemspec +28 -0
- data/lib/guard/sidekiq/templates/Guardfile +10 -0
- data/lib/guard/sidekiq/version.rb +7 -0
- data/lib/guard/sidekiq.rb +95 -0
- data/lib/guard-sidekiq.rb +1 -0
- data/spec/guard/sidekiq_spec.rb +47 -0
- data/spec/spec_helper.rb +10 -0
- metadata +144 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## 0.0.3
|
2
|
+
|
3
|
+
* Forked from guard-delayed and guard-resque
|
4
|
+
|
5
|
+
|
6
|
+
-- guard-delayed --
|
7
|
+
|
8
|
+
## 0.1.0 (2011-07-28)
|
9
|
+
|
10
|
+
* Fixed options for current delayed_job version (from dbloete)
|
11
|
+
* Environment settings needed to be passed in via RAILS_ENV=
|
12
|
+
|
13
|
+
## 0.0.9 (2011-06-22)
|
14
|
+
|
15
|
+
* Fixed argument passing to the start script
|
16
|
+
* Cleaned up some documentation.
|
17
|
+
|
18
|
+
## 0.0.8 (2011-05-24)
|
19
|
+
|
20
|
+
* Changed template to include :environment => 'development'
|
21
|
+
* Changed name from 'guard-delayed_job' to 'guard-delayed'
|
22
|
+
* Fixed options passing
|
23
|
+
|
24
|
+
## 0.0.3 (2011-05-23)
|
25
|
+
|
26
|
+
* Initial release.
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Guard::Sidekiq
|
2
|
+
|
3
|
+
Guard::Sidekiq automatically starts/stops/restarts Sidekiq workers
|
4
|
+
|
5
|
+
*forked from [Guard::Resque](https://github.com/guard/guard-resque)*
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Please be sure to have [Guard](http://github.com/guard/guard) installed before continue.
|
10
|
+
|
11
|
+
Install the gem:
|
12
|
+
|
13
|
+
gem install guard-sidekiq
|
14
|
+
|
15
|
+
Add it to your Gemfile (inside test group):
|
16
|
+
|
17
|
+
gem 'guard-sidekiq'
|
18
|
+
|
19
|
+
Add guard definition to your Guardfile by running this command:
|
20
|
+
|
21
|
+
guard init sidekiq
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Please read [Guard usage doc](http://github.com/guard/guard#readme).
|
26
|
+
|
27
|
+
I suggest you put the sidekiq guard definition *before* your test/rspec guard if your tests depend on it
|
28
|
+
being active.
|
29
|
+
|
30
|
+
## Guardfile
|
31
|
+
|
32
|
+
guard 'sidekiq', :environment => 'development' do
|
33
|
+
watch(%r{^workers/(.+)\.rb})
|
34
|
+
end
|
35
|
+
|
36
|
+
## Options
|
37
|
+
|
38
|
+
You can customize the sidekiq task via the following options:
|
39
|
+
|
40
|
+
* `environment`: the rails environment to run the workers in (defaults to `nil`)
|
41
|
+
* `queue`: the sidekiq queue to run (defaults to `"*"`)
|
42
|
+
* `timeout`: shutdown timeout
|
43
|
+
* `concurrency`: the number of threads to include (defaults to `1`)
|
44
|
+
* `verbose`: whether to use verbose logging (defaults to `nil`)
|
45
|
+
* `stop_signal`: how to kill the process when restarting (defaults to `QUIT`)
|
46
|
+
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
* Source hosted at [GitHub](http://github.com/uken/guard-sidekiq)
|
51
|
+
* Report issues/Questions/Feature requests on [GitHub Issues](http://github.com/uken/guard-sidekiq/issues)
|
52
|
+
|
53
|
+
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
|
54
|
+
you make.
|
55
|
+
|
56
|
+
## Testing the gem locally
|
57
|
+
|
58
|
+
gem install guard-sidekiq-0.x.x.gem
|
59
|
+
|
60
|
+
## Building and deploying gem
|
61
|
+
|
62
|
+
* Update the version number in `lib/guard/sidekiq/version.rb`
|
63
|
+
* Update `CHANGELOG.md`
|
64
|
+
* Build the gem:
|
65
|
+
|
66
|
+
gem build guard-sidekiq.gemspec
|
67
|
+
|
68
|
+
* Push to rubygems.org:
|
69
|
+
|
70
|
+
gem push guard-sidekiq-0.x.x.gem
|
71
|
+
|
72
|
+
## Guard::Delayed Authors
|
73
|
+
|
74
|
+
[David Parry](https://github.com/suranyami)
|
75
|
+
[Dennis Reimann](https://github.com/dbloete)
|
76
|
+
|
77
|
+
Ideas for this gem came from [Guard::WEBrick](http://github.com/fnichol/guard-webrick).
|
78
|
+
|
79
|
+
|
80
|
+
## Guard::Resque Authors
|
81
|
+
|
82
|
+
[Jacques Crocker](https://github.com/railsjedi)
|
83
|
+
|
84
|
+
I hacked this together from the `guard-delayed` gem for use with Resque. All credit go to the original authors though. I just search/replaced and tweaked a few things
|
85
|
+
|
86
|
+
## Guard::Sidekiq Authors
|
87
|
+
Mark Bolusmjak
|
88
|
+
Pitr Vernigorov
|
89
|
+
|
90
|
+
Replaces "rescue" with "sidekiq"
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "guard/sidekiq/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guard-sidekiq"
|
7
|
+
s.version = Guard::Sidekiq::Version::STRING
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Mark Bolusmjak", "pitr"]
|
10
|
+
s.email = ["team@uken.com"]
|
11
|
+
s.homepage = 'http://github.com/uken/guard-sidekiq'
|
12
|
+
s.summary = %q{guard gem for sidekiq}
|
13
|
+
s.description = %q{Guard::Sidekiq automatically starts/stops/restarts sidekiq worker}
|
14
|
+
|
15
|
+
s.add_dependency 'guard', '>= 0.8'
|
16
|
+
s.add_dependency 'sidekiq'
|
17
|
+
|
18
|
+
s.add_development_dependency 'bundler'
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
s.add_development_dependency 'rspec', '~> 2.5.0'
|
21
|
+
s.add_development_dependency 'guard-rspec', '>= 0.2.0'
|
22
|
+
s.add_development_dependency 'guard-bundler', '>= 0.1.1'
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
### Guard::Sidekiq
|
2
|
+
# available options:
|
3
|
+
# - :verbose
|
4
|
+
# - :queue (defaults to "*")
|
5
|
+
# - :concurrency (defaults to 1)
|
6
|
+
# - :timeout
|
7
|
+
# - :environment (corresponds to RAILS_ENV for the Sidekiq worker)
|
8
|
+
guard 'sidekiq', :environment => 'development' do
|
9
|
+
watch(%r{^workers/(.+)\.rb$})
|
10
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class Sidekiq < Guard
|
6
|
+
|
7
|
+
DEFAULT_SIGNAL = :QUIT
|
8
|
+
DEFAULT_QUEUE = '*'.freeze
|
9
|
+
DEFAULT_CONCURRENCY = 1
|
10
|
+
|
11
|
+
# Allowable options are:
|
12
|
+
# - :environment e.g. 'test'
|
13
|
+
# - :queue e.g. '*'
|
14
|
+
# - :timeout e.g. 5
|
15
|
+
# - :concurrency, e.g. 20
|
16
|
+
# - :verbose e.g. true
|
17
|
+
# - :stop_signal e.g. :QUIT or :SIGQUIT
|
18
|
+
def initialize(watchers = [], options = {})
|
19
|
+
@options = options
|
20
|
+
@pid = nil
|
21
|
+
@stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
|
22
|
+
@options[:queue] ||= DEFAULT_QUEUE
|
23
|
+
@options[:concurrency] ||= DEFAULT_CONCURRENCY
|
24
|
+
@options[:verbose] = @options.fetch(:verbose, true)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
stop
|
30
|
+
UI.info 'Starting up sidekiq...'
|
31
|
+
UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ')
|
32
|
+
|
33
|
+
# launch Sidekiq worker
|
34
|
+
@pid = spawn(env, cmd)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
if @pid
|
39
|
+
UI.info 'Stopping sidekiq...'
|
40
|
+
::Process.kill @stop_signal, @pid
|
41
|
+
begin
|
42
|
+
Timeout.timeout(15) do
|
43
|
+
::Process.wait @pid
|
44
|
+
end
|
45
|
+
rescue Timeout::Error
|
46
|
+
UI.info 'Sending SIGKILL to sidekiq, as it\'s taking too long to shutdown.'
|
47
|
+
::Process.kill :KILL, @pid
|
48
|
+
::Process.wait @pid
|
49
|
+
end
|
50
|
+
UI.info 'Stopped process sidekiq'
|
51
|
+
end
|
52
|
+
rescue Errno::ESRCH
|
53
|
+
UI.info 'Guard::Sidekiq lost the Sidekiq worker subprocess!'
|
54
|
+
ensure
|
55
|
+
@pid = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# Called on Ctrl-Z signal
|
59
|
+
def reload
|
60
|
+
UI.info 'Restarting sidekiq...'
|
61
|
+
restart
|
62
|
+
end
|
63
|
+
|
64
|
+
# Called on Ctrl-/ signal
|
65
|
+
def run_all
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
# Called on file(s) modifications
|
70
|
+
def run_on_change(paths)
|
71
|
+
restart
|
72
|
+
end
|
73
|
+
|
74
|
+
def restart
|
75
|
+
stop
|
76
|
+
start
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def cmd
|
82
|
+
command = ['bundle exec sidekiq']
|
83
|
+
|
84
|
+
# trace setting
|
85
|
+
command << "--queue #{@options[:queue]}"
|
86
|
+
command << "--verbose" if @options[:verbose]
|
87
|
+
command << "--environment #{@options[:environment]}" if @options[:environment]
|
88
|
+
command << "--timeout #{@options[:timeout]}" if @options[:timeout]
|
89
|
+
command << "--concurrency #{@options[:concurrency]}"
|
90
|
+
|
91
|
+
command.join(' ')
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'guard/sidekiq'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::Sidekiq do
|
4
|
+
describe 'start' do
|
5
|
+
|
6
|
+
it 'should accept :environment option' do
|
7
|
+
environment = :foo
|
8
|
+
|
9
|
+
obj = Guard::Sidekiq.new [], :environment => environment
|
10
|
+
obj.send(:cmd).should include "--environment #{environment}"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should accept :queue option' do
|
14
|
+
queue = :foo
|
15
|
+
|
16
|
+
obj = Guard::Sidekiq.new [], :queue => queue
|
17
|
+
obj.send(:cmd).should include "--queue #{queue}"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should accept :timeout option' do
|
21
|
+
timeout = 2
|
22
|
+
|
23
|
+
obj = Guard::Sidekiq.new [], :timeout => timeout
|
24
|
+
obj.send(:cmd).should include "--timeout #{timeout}"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should accept :concurrency option' do
|
28
|
+
concurrency = 2
|
29
|
+
|
30
|
+
obj = Guard::Sidekiq.new [], :concurrency => concurrency
|
31
|
+
obj.send(:cmd).should include "--concurrency #{concurrency}"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should accept :verbose option' do
|
35
|
+
obj = Guard::Sidekiq.new [], :verbose => true
|
36
|
+
obj.send(:cmd).should include '--verbose'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should provide default options' do
|
40
|
+
obj = Guard::Sidekiq.new []
|
41
|
+
obj.send(:cmd).should include "--queue #{Guard::Sidekiq::DEFAULT_QUEUE}"
|
42
|
+
obj.send(:cmd).should include "--concurrency #{Guard::Sidekiq::DEFAULT_CONCURRENCY}"
|
43
|
+
obj.send(:cmd).should include '--verbose'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Bolusmjak
|
9
|
+
- pitr
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-06-21 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: guard
|
17
|
+
requirement: &70334955149000 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.8'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70334955149000
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: sidekiq
|
28
|
+
requirement: &70334955147120 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70334955147120
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &70334955145740 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70334955145740
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &70334955144980 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70334955144980
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: &70334955143860 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.5.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70334955143860
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
72
|
+
requirement: &70334955142460 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.2.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70334955142460
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: guard-bundler
|
83
|
+
requirement: &70334955141820 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.1.1
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *70334955141820
|
92
|
+
description: Guard::Sidekiq automatically starts/stops/restarts sidekiq worker
|
93
|
+
email:
|
94
|
+
- team@uken.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- CHANGELOG.md
|
101
|
+
- Gemfile
|
102
|
+
- Guardfile
|
103
|
+
- README.markdown
|
104
|
+
- Rakefile
|
105
|
+
- guard-sidekiq.gemspec
|
106
|
+
- lib/guard-sidekiq.rb
|
107
|
+
- lib/guard/sidekiq.rb
|
108
|
+
- lib/guard/sidekiq/templates/Guardfile
|
109
|
+
- lib/guard/sidekiq/version.rb
|
110
|
+
- spec/guard/sidekiq_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
homepage: http://github.com/uken/guard-sidekiq
|
113
|
+
licenses: []
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: -3647367652343109123
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: -3647367652343109123
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.15
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: guard gem for sidekiq
|
142
|
+
test_files:
|
143
|
+
- spec/guard/sidekiq_spec.rb
|
144
|
+
- spec/spec_helper.rb
|