guard-resque 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/CHANGELOG.md +9 -2
- data/README.markdown +11 -10
- data/Rakefile +21 -20
- data/guard-resque.gemspec +4 -3
- data/lib/guard/resque.rb +53 -35
- data/lib/guard/resque/templates/Guardfile +10 -8
- data/lib/guard/resque/version.rb +1 -1
- data/spec/guard/resque_spec.rb +44 -28
- data/spec/spec_helper.rb +1 -1
- metadata +32 -20
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
## 0.0.
|
1
|
+
## 0.0.4
|
2
|
+
|
3
|
+
* Add a :vverbose option to distinguish from the :verbose option
|
4
|
+
* Add a timeout when killing Resque, to force it with SIGKILL
|
5
|
+
* Change the way the #spawn call is made, so it doesn't create a subshell to launch
|
6
|
+
Resque, which was causing issue #2
|
7
|
+
|
8
|
+
## 0.0.3
|
2
9
|
|
3
10
|
* Forked from guard-delayed and started guard-resque
|
4
11
|
|
@@ -9,7 +16,7 @@
|
|
9
16
|
|
10
17
|
* Fixed options for current delayed_job version (from dbloete)
|
11
18
|
* Environment settings needed to be passed in via RAILS_ENV=
|
12
|
-
|
19
|
+
|
13
20
|
## 0.0.9 (2011-06-22)
|
14
21
|
|
15
22
|
* Fixed argument passing to the start script
|
data/README.markdown
CHANGED
@@ -32,18 +32,19 @@ being active.
|
|
32
32
|
guard 'resque', :environment => 'development' do
|
33
33
|
watch(%r{^app/(.+)\.rb})
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
## Options
|
37
37
|
|
38
38
|
You can customize the resque task via the following options:
|
39
39
|
|
40
|
-
* `environment`: the rails environment to run the workers in (defaults to `
|
40
|
+
* `environment`: the rails environment to run the workers in (defaults to `nil`)
|
41
41
|
* `task`: the name of the rake task to use (defaults to `"resque:work"`)
|
42
42
|
* `queue`: the resque queue to run (defaults to `"*"`)
|
43
|
-
* `count`: the number of workers to include (defaults to `
|
44
|
-
* `verbose`: whether to use verbose logging (defaults to `
|
45
|
-
* `
|
46
|
-
* `
|
43
|
+
* `count`: the number of workers to include (defaults to `1`)
|
44
|
+
* `verbose`: whether to use verbose logging (defaults to `nil`)
|
45
|
+
* `vverbose`: whether to use very verbose logging (defaults to `nil`)
|
46
|
+
* `trace`: whether to include `--trace` on the rake command (defaults to `nil`)
|
47
|
+
* `stop_signal`: how to kill the process when restarting (defaults to `QUIT`)
|
47
48
|
|
48
49
|
|
49
50
|
## Development
|
@@ -63,13 +64,13 @@ you make.
|
|
63
64
|
* Update the version number in `lib/guard/resque/version.rb`
|
64
65
|
* Update `CHANGELOG.md`
|
65
66
|
* Build the gem:
|
66
|
-
|
67
|
+
|
67
68
|
gem build guard-resque.gemspec
|
68
|
-
|
69
|
+
|
69
70
|
* Push to rubygems.org:
|
70
|
-
|
71
|
+
|
71
72
|
gem push guard-resque-0.x.x.gem
|
72
|
-
|
73
|
+
|
73
74
|
|
74
75
|
## Guard::Delayed Authors
|
75
76
|
|
data/Rakefile
CHANGED
@@ -5,28 +5,29 @@ require 'rspec/core/rake_task'
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
task :default => :spec
|
7
7
|
|
8
|
-
namespace
|
8
|
+
namespace :spec do
|
9
9
|
desc "Run all specs on multiple ruby versions (requires rvm)"
|
10
|
-
task
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
rake spec'
|
10
|
+
task :portability do
|
11
|
+
|
12
|
+
command = <<-BASH
|
13
|
+
source ~/.rvm/scripts/rvm;
|
14
|
+
rvm #{ENV['RUBIES'] || 'all'} do bundle exec rake spec
|
15
|
+
BASH
|
16
|
+
system "bash -c '#{command}'"
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :portability do
|
21
|
+
desc 'Installs bundler/rake and runs bundle install for all rubies'
|
22
|
+
task :prepare do
|
23
|
+
# FIXME: This isn't working for me when it gets to JRuby, specs are running fine - RL
|
24
|
+
command = <<-BASH
|
25
|
+
source ~/.rvm/scripts/rvm;
|
26
|
+
rvm #{ENV['RUBIES'] || 'all'} do gem install bundler rake;
|
27
|
+
rvm #{ENV['RUBIES'] || 'all'} do bundle install
|
29
28
|
BASH
|
29
|
+
|
30
|
+
system "bash -c '#{command}'"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
data/guard-resque.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "guard-resque"
|
7
7
|
s.version = Guard::ResqueVersion::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Jacques Crocker", "David Parry"]
|
10
|
-
s.email = ["railsjedi@gmail.com"]
|
9
|
+
s.authors = ["Jacques Crocker", "Ryan Long", "David Parry"]
|
10
|
+
s.email = ["railsjedi@gmail.com", 'ryan@rtlong.com']
|
11
11
|
s.homepage = 'http://github.com/railsjedi/guard-resque'
|
12
12
|
s.summary = %q{guard gem for resque}
|
13
13
|
s.description = %q{Guard::Resque automatically starts/stops/restarts resque worker}
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'guard', '>= 0.8'
|
19
19
|
s.add_dependency 'resque'
|
20
20
|
|
21
|
-
s.add_development_dependency 'bundler'
|
21
|
+
s.add_development_dependency 'bundler'
|
22
|
+
s.add_development_dependency 'rake'
|
22
23
|
s.add_development_dependency 'rspec', '~> 2.5.0'
|
23
24
|
s.add_development_dependency 'guard-rspec', '>= 0.2.0'
|
24
25
|
s.add_development_dependency 'guard-bundler', '>= 0.1.1'
|
data/lib/guard/resque.rb
CHANGED
@@ -4,48 +4,68 @@ require 'guard/guard'
|
|
4
4
|
module Guard
|
5
5
|
class Resque < Guard
|
6
6
|
|
7
|
+
DEFAULT_SIGNAL = :QUIT
|
8
|
+
DEFAULT_QUEUE = '*'.freeze
|
9
|
+
DEFAULT_COUNT = 1
|
10
|
+
DEFAULT_TASK_SINGLE = 'resque:work'.freeze
|
11
|
+
DEFAULT_TASK_MULTIPLE = 'resque:workers'.freeze
|
12
|
+
|
7
13
|
# Allowable options are:
|
8
|
-
# :environment e.g. 'test'
|
9
|
-
# :task .e.g 'resque:work'
|
10
|
-
# :queue e.g. '*'
|
11
|
-
# :count e.g. 3
|
12
|
-
# :verbose e.g. true
|
13
|
-
# :
|
14
|
-
# :
|
14
|
+
# - :environment e.g. 'test'
|
15
|
+
# - :task .e.g 'resque:work'
|
16
|
+
# - :queue e.g. '*'
|
17
|
+
# - :count e.g. 3
|
18
|
+
# - :verbose e.g. true
|
19
|
+
# - :vverbose e.g. true
|
20
|
+
# - :trace e.g. true
|
21
|
+
# - :stop_signal e.g. :QUIT or :SIGQUIT
|
15
22
|
def initialize(watchers = [], options = {})
|
16
23
|
@options = options
|
17
24
|
@pid = nil
|
18
|
-
@stop_signal = options[:stop_signal] ||
|
25
|
+
@stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
|
26
|
+
@options[:queue] ||= DEFAULT_QUEUE
|
27
|
+
@options[:count] ||= DEFAULT_COUNT
|
28
|
+
@options[:task] ||= (@options[:count].to_i == 1) ? DEFAULT_TASK_SINGLE : DEFAULT_TASK_MULTIPLE
|
19
29
|
super
|
20
30
|
end
|
21
31
|
|
22
32
|
def start
|
23
33
|
stop
|
24
|
-
UI.info
|
25
|
-
UI.info cmd
|
26
|
-
|
34
|
+
UI.info 'Starting up resque...'
|
35
|
+
UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ')
|
36
|
+
|
37
|
+
# launch Resque worker
|
38
|
+
@pid = spawn(env, cmd)
|
27
39
|
end
|
28
40
|
|
29
|
-
# Called on Ctrl-C signal (when Guard quits)
|
30
41
|
def stop
|
31
42
|
if @pid
|
32
|
-
UI.info
|
33
|
-
::Process.kill
|
34
|
-
|
35
|
-
|
36
|
-
|
43
|
+
UI.info 'Stopping resque...'
|
44
|
+
::Process.kill @stop_signal, @pid
|
45
|
+
begin
|
46
|
+
Timeout.timeout(15) do
|
47
|
+
::Process.wait @pid
|
48
|
+
end
|
49
|
+
rescue Timeout::Error
|
50
|
+
UI.info 'Sending SIGKILL to resque, as it\'s taking too long to shutdown.'
|
51
|
+
::Process.kill :KILL, @pid
|
52
|
+
::Process.wait @pid
|
53
|
+
end
|
54
|
+
UI.info 'Stopped process resque'
|
37
55
|
end
|
56
|
+
rescue Errno::ESRCH
|
57
|
+
UI.info 'Guard::Resque lost the Resque worker subprocess!'
|
58
|
+
ensure
|
59
|
+
@pid = nil
|
38
60
|
end
|
39
61
|
|
40
62
|
# Called on Ctrl-Z signal
|
41
|
-
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
42
63
|
def reload
|
43
|
-
UI.info
|
64
|
+
UI.info 'Restarting resque...'
|
44
65
|
restart
|
45
66
|
end
|
46
67
|
|
47
68
|
# Called on Ctrl-/ signal
|
48
|
-
# This method should be principally used for long action like running all specs/tests/...
|
49
69
|
def run_all
|
50
70
|
true
|
51
71
|
end
|
@@ -63,27 +83,25 @@ module Guard
|
|
63
83
|
private
|
64
84
|
|
65
85
|
def cmd
|
66
|
-
command =
|
67
|
-
|
68
|
-
# environment setting
|
69
|
-
command << "RAILS_ENV=#{@options[:environment]} " if @options[:environment]
|
86
|
+
command = ['bundle exec rake', @options[:task].to_s]
|
70
87
|
|
71
|
-
#
|
72
|
-
command <<
|
88
|
+
# trace setting
|
89
|
+
command << '--trace' if @options[:trace]
|
73
90
|
|
74
|
-
|
75
|
-
|
91
|
+
return command.join(' ')
|
92
|
+
end
|
76
93
|
|
77
|
-
|
78
|
-
|
94
|
+
def env
|
95
|
+
var = Hash.new
|
79
96
|
|
80
|
-
|
81
|
-
|
97
|
+
var['QUEUE'] = @options[:queue].to_s if @options[:queue]
|
98
|
+
var['COUNT'] = @options[:count].to_s if @options[:count]
|
99
|
+
var['RAILS_ENV'] = @options[:environment].to_s if @options[:environment]
|
82
100
|
|
83
|
-
|
84
|
-
|
101
|
+
var['VERBOSE'] = '1' if @options[:verbose]
|
102
|
+
var['VVERBOSE'] = '1' if @options[:vverbose]
|
85
103
|
|
86
|
-
|
104
|
+
return var
|
87
105
|
end
|
88
106
|
end
|
89
107
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
# :
|
3
|
-
# :
|
4
|
-
# :
|
5
|
-
# :
|
6
|
-
# :
|
1
|
+
### Guard::Resque
|
2
|
+
# available options:
|
3
|
+
# - :task (defaults to 'resque:work' if :count is 1; 'resque:workers', otherwise)
|
4
|
+
# - :verbose / :vverbose (set them to anything but false to activate their respective modes)
|
5
|
+
# - :trace
|
6
|
+
# - :queue (defaults to "*")
|
7
|
+
# - :count (defaults to 1)
|
8
|
+
# - :environment (corresponds to RAILS_ENV for the Resque worker)
|
7
9
|
guard 'resque', :environment => 'development' do
|
8
|
-
watch(%r{^app/(.+)\.rb})
|
9
|
-
watch(%r{^lib/(.+)\.rb})
|
10
|
+
watch(%r{^app/(.+)\.rb$})
|
11
|
+
watch(%r{^lib/(.+)\.rb$})
|
10
12
|
end
|
data/lib/guard/resque/version.rb
CHANGED
data/spec/guard/resque_spec.rb
CHANGED
@@ -1,51 +1,67 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Guard::Resque do
|
4
|
-
|
4
|
+
describe 'start' do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
subject = Guard::Resque.new
|
9
|
-
end
|
6
|
+
it 'should accept :environment option' do
|
7
|
+
environment = :foo
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
obj = Guard::Resque.new [], :environment => environment
|
10
|
+
obj.send(:env).should include 'RAILS_ENV' => environment.to_s
|
13
11
|
end
|
14
12
|
|
15
|
-
it
|
16
|
-
|
17
|
-
Dir.glob("tmp/pids/resque*.pid").should_not be_empty
|
18
|
-
end
|
13
|
+
it 'should accept :queue option' do
|
14
|
+
queue = :foo
|
19
15
|
|
20
|
-
|
21
|
-
obj
|
22
|
-
obj.send(:cmd).should match /RAILS_ENV=foo/
|
16
|
+
obj = Guard::Resque.new [], :queue => queue
|
17
|
+
obj.send(:env).should include 'QUEUE' => queue.to_s
|
23
18
|
end
|
24
19
|
|
25
|
-
it
|
26
|
-
|
27
|
-
|
20
|
+
it 'should accept :count option' do
|
21
|
+
count = 2
|
22
|
+
|
23
|
+
obj = Guard::Resque.new [], :count => count
|
24
|
+
obj.send(:env).should include 'COUNT' => count.to_s
|
28
25
|
end
|
29
26
|
|
30
|
-
it
|
31
|
-
obj = Guard::Resque.new [], :
|
32
|
-
obj.send(:
|
27
|
+
it 'should accept :vverbose option' do
|
28
|
+
obj = Guard::Resque.new [], :vverbose => true
|
29
|
+
obj.send(:env).should include 'VVERBOSE'
|
33
30
|
end
|
34
31
|
|
35
|
-
it
|
32
|
+
it 'should accept :verbose option' do
|
36
33
|
obj = Guard::Resque.new [], :verbose => true
|
37
|
-
obj.send(:
|
34
|
+
obj.send(:env).should include 'VERBOSE'
|
38
35
|
end
|
39
36
|
|
40
|
-
it
|
37
|
+
it 'should accept :trace option' do
|
41
38
|
obj = Guard::Resque.new [], :trace => true
|
42
|
-
obj.send(:cmd).should
|
39
|
+
obj.send(:cmd).should include '--trace'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should accept :task option' do
|
43
|
+
task = 'environment foo'
|
44
|
+
|
45
|
+
obj = Guard::Resque.new [], :task => task
|
46
|
+
obj.send(:cmd).should include task
|
47
|
+
obj.send(:cmd).should_not include Guard::Resque::DEFAULT_TASK_SINGLE
|
43
48
|
end
|
44
49
|
|
45
|
-
it
|
46
|
-
obj = Guard::Resque.new []
|
47
|
-
obj.send(:
|
48
|
-
obj.send(:
|
50
|
+
it 'should provide default options' do
|
51
|
+
obj = Guard::Resque.new []
|
52
|
+
obj.send(:env).should include 'QUEUE' => Guard::Resque::DEFAULT_QUEUE.to_s
|
53
|
+
obj.send(:env).should include 'COUNT' => Guard::Resque::DEFAULT_COUNT.to_s
|
54
|
+
obj.send(:cmd).should include Guard::Resque::DEFAULT_TASK_SINGLE
|
49
55
|
end
|
56
|
+
|
57
|
+
it 'should provide different default options when :count is multiple' do
|
58
|
+
count = 2
|
59
|
+
|
60
|
+
obj = Guard::Resque.new [], :count => count
|
61
|
+
obj.send(:env).should include 'QUEUE' => Guard::Resque::DEFAULT_QUEUE.to_s
|
62
|
+
obj.send(:env).should include 'COUNT' => count.to_s
|
63
|
+
obj.send(:cmd).should include Guard::Resque::DEFAULT_TASK_MULTIPLE
|
64
|
+
end
|
65
|
+
|
50
66
|
end
|
51
67
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-resque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jacques Crocker
|
9
|
+
- Ryan Long
|
9
10
|
- David Parry
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2012-02-20 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: guard
|
17
|
-
requirement: &
|
18
|
+
requirement: &9480740 !ruby/object:Gem::Requirement
|
18
19
|
none: false
|
19
20
|
requirements:
|
20
21
|
- - ! '>='
|
@@ -22,10 +23,10 @@ dependencies:
|
|
22
23
|
version: '0.8'
|
23
24
|
type: :runtime
|
24
25
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
+
version_requirements: *9480740
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
28
|
name: resque
|
28
|
-
requirement: &
|
29
|
+
requirement: &9480060 !ruby/object:Gem::Requirement
|
29
30
|
none: false
|
30
31
|
requirements:
|
31
32
|
- - ! '>='
|
@@ -33,21 +34,32 @@ dependencies:
|
|
33
34
|
version: '0'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
+
version_requirements: *9480060
|
37
38
|
- !ruby/object:Gem::Dependency
|
38
39
|
name: bundler
|
39
|
-
requirement: &
|
40
|
+
requirement: &9478340 !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
|
-
- -
|
43
|
+
- - ! '>='
|
43
44
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
+
version: '0'
|
45
46
|
type: :development
|
46
47
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
+
version_requirements: *9478340
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
requirement: &9477480 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *9477480
|
48
60
|
- !ruby/object:Gem::Dependency
|
49
61
|
name: rspec
|
50
|
-
requirement: &
|
62
|
+
requirement: &9493020 !ruby/object:Gem::Requirement
|
51
63
|
none: false
|
52
64
|
requirements:
|
53
65
|
- - ~>
|
@@ -55,10 +67,10 @@ dependencies:
|
|
55
67
|
version: 2.5.0
|
56
68
|
type: :development
|
57
69
|
prerelease: false
|
58
|
-
version_requirements: *
|
70
|
+
version_requirements: *9493020
|
59
71
|
- !ruby/object:Gem::Dependency
|
60
72
|
name: guard-rspec
|
61
|
-
requirement: &
|
73
|
+
requirement: &9492080 !ruby/object:Gem::Requirement
|
62
74
|
none: false
|
63
75
|
requirements:
|
64
76
|
- - ! '>='
|
@@ -66,10 +78,10 @@ dependencies:
|
|
66
78
|
version: 0.2.0
|
67
79
|
type: :development
|
68
80
|
prerelease: false
|
69
|
-
version_requirements: *
|
81
|
+
version_requirements: *9492080
|
70
82
|
- !ruby/object:Gem::Dependency
|
71
83
|
name: guard-bundler
|
72
|
-
requirement: &
|
84
|
+
requirement: &9491100 !ruby/object:Gem::Requirement
|
73
85
|
none: false
|
74
86
|
requirements:
|
75
87
|
- - ! '>='
|
@@ -77,10 +89,11 @@ dependencies:
|
|
77
89
|
version: 0.1.1
|
78
90
|
type: :development
|
79
91
|
prerelease: false
|
80
|
-
version_requirements: *
|
92
|
+
version_requirements: *9491100
|
81
93
|
description: Guard::Resque automatically starts/stops/restarts resque worker
|
82
94
|
email:
|
83
95
|
- railsjedi@gmail.com
|
96
|
+
- ryan@rtlong.com
|
84
97
|
executables: []
|
85
98
|
extensions: []
|
86
99
|
extra_rdoc_files: []
|
@@ -118,10 +131,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
131
|
version: 1.3.6
|
119
132
|
requirements: []
|
120
133
|
rubyforge_project: guard-resque
|
121
|
-
rubygems_version: 1.8.
|
134
|
+
rubygems_version: 1.8.15
|
122
135
|
signing_key:
|
123
136
|
specification_version: 3
|
124
137
|
summary: guard gem for resque
|
125
|
-
test_files:
|
126
|
-
|
127
|
-
- spec/spec_helper.rb
|
138
|
+
test_files: []
|
139
|
+
has_rdoc:
|