Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first shot at switching things to resque

  • Loading branch information...
commit 17d571b0b03d4d14890fa90800954ee2120534c2 1 parent 099f663
@railsjedi authored
View
7 CHANGELOG.md
@@ -1,3 +1,10 @@
+## 0.0.1
+
+ * Forked from guard-delayed and started guard-resque
+
+
+-- guard-delayed --
+
## 0.1.0 (2011-07-28)
* Fixed options for current delayed_job version (from dbloete)
View
2  Gemfile
@@ -1,4 +1,4 @@
source "http://rubygems.org"
-# Specify your gem's dependencies in guard-delayed.gemspec
+# Specify your gem's dependencies in guard-resque.gemspec
gemspec
View
41 README.markdown
@@ -1,6 +1,8 @@
-# Guard::Delayed
+# Guard::Resque
-Guard::Delayed automatically starts/stops/restarts delayed_job
+Guard::Resque automatically starts/stops/restarts resque workers
+
+*forked from [Guard::Delayed](http://github.com/suranyami/guard-delayed)*
## Install
@@ -8,63 +10,66 @@ Please be sure to have [Guard](http://github.com/guard/guard) installed before c
Install the gem:
- gem install guard-delayed
+ gem install guard-resque
Add it to your Gemfile (inside test group):
- gem 'guard-delayed'
+ gem 'guard-resque'
Add guard definition to your Guardfile by running this command:
- guard init delayed
+ guard init resque
## Usage
Please read [Guard usage doc](http://github.com/guard/guard#readme).
-I suggest you put the delayed guard definition *before* your test/rspec guard if your tests depend on it
+I suggest you put the resque guard definition *before* your test/rspec guard if your tests depend on it
being active.
## Guardfile
- guard 'delayed', :environment => 'development' do
+ guard 'resque', :environment => 'development' do
watch(%r{^app/(.+)\.rb})
end
## Development
- * Source hosted at [GitHub](http://github.com/suranyami/guard-delayed)
- * Report issues/Questions/Feature requests on [GitHub Issues](http://github.com/suranyami/guard-delayed/issues)
+ * Source hosted at [GitHub](http://github.com/railsjedi/guard-resque)
+ * Report issues/Questions/Feature requests on [GitHub Issues](http://github.com/railsjedi/guard-resque/issues)
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
you make.
## Testing the gem locally
- gem install guard-delayed-0.1.1.gem
+ gem install guard-resque-0.x.x.gem
## Building and deploying gem
- * Update the version number in `lib/guard/delayed/version.rb`
+ * Update the version number in `lib/guard/resque/version.rb`
* Update `CHANGELOG.md`
* Build the gem:
- gem build guard-delayed.gemspec
+ gem build guard-resque.gemspec
* Push to rubygems.org:
- gem push guard-delayed-0.1.1.gem
+ gem push guard-resque-0.x.x.gem
-## Authors
+## Guard::Delayed Authors
[David Parry](https://github.com/suranyami)
[Dennis Reimann](https://github.com/dbloete)
Ideas for this gem came from [Guard::WEBrick](http://github.com/fnichol/guard-webrick).
-## Note
-I originally called this `guard-delayed_job` but had all sorts of unexpected behaviour when trying to build the gem.
-After much fruitless investigation it appeared that the underscore was the problem, so I renamed it to `guard-delayed`.
-Anybody else encountered this? Let me know if you have. Thanks in advance.
+## Guard::Resque Authors
+
+[Jacques Crocker](https://github.com/railsjedi)
+
+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
+
+
View
30 guard-delayed.gemspec
@@ -1,30 +0,0 @@
-# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
-require "guard/delayed/version"
-
-Gem::Specification.new do |s|
- s.name = "guard-delayed"
- s.version = Guard::DelayedVersion::VERSION
- s.platform = Gem::Platform::RUBY
- s.authors = ["David Parry"]
- s.email = ["david.parry@suranyami.com"]
- s.homepage = 'http://rubygems.org/gems/guard-delayed'
- s.summary = %q{guard gem for delayed_job}
- s.description = %q{Guard::Delayedjob automatically starts/stops/restarts delayed_job}
-
- s.required_rubygems_version = '>= 1.3.6'
- s.rubyforge_project = "guard-delayed"
-
- s.add_dependency 'guard', '~> 0.3'
- s.add_dependency 'delayed_job'
-
- s.add_development_dependency 'bundler', '~> 1.0.10'
- s.add_development_dependency 'rspec', '~> 2.5.0'
- s.add_development_dependency 'guard-rspec', '~> 0.2.0'
- s.add_development_dependency 'guard-bundler', '~> 0.1.1'
-
- s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
-end
View
30 guard-resque.gemspec
@@ -0,0 +1,30 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "guard/resque/version"
+
+Gem::Specification.new do |s|
+ s.name = "guard-resque"
+ s.version = Guard::ResqueVersion::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Jacques Crocker", "David Parry"]
+ s.email = ["railsjedi@gmail.com"]
+ s.homepage = 'http://github.com/railsjedi/guard-resque'
+ s.summary = %q{guard gem for resque}
+ s.description = %q{Guard::Resque automatically starts/stops/restarts resque worker}
+
+ s.required_rubygems_version = '>= 1.3.6'
+ s.rubyforge_project = "guard-resque"
+
+ s.add_dependency 'guard', '>= 0.8'
+ s.add_dependency 'resque'
+
+ s.add_development_dependency 'bundler', '~> 1.0.10'
+ s.add_development_dependency 'rspec', '~> 2.5.0'
+ s.add_development_dependency 'guard-rspec', '>= 0.2.0'
+ s.add_development_dependency 'guard-bundler', '>= 0.1.1'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
View
1  lib/guard-delayed.rb
@@ -1 +0,0 @@
-require 'guard/delayed'
View
1  lib/guard-resque.rb
@@ -0,0 +1 @@
+require 'guard/resque'
View
74 lib/guard/delayed.rb
@@ -1,74 +0,0 @@
-require 'guard'
-require 'guard/guard'
-
-module Guard
- class Delayed < Guard
-
- # Allowable options are:
- # :environment e.g. 'test'
- # :min_priority e.g. 2
- # :max_priority e.g. 10
- # :number_of_workers e.g. 2
- # :pid_dir e.g. tmp/pids Specifies an alternate directory in which to store the process ids.
- # :identifier A numeric identifier for the worker.
- # :monitor Start monitor process.
- # :sleep-delay N Amount of time to sleep in seconds when no jobs are found
- # :prefix NAME String to be prefixed to worker process names
-
- def initialize(watchers = [], options = {})
- @options = options
- super
- end
-
- def start
- system(cmd, 'stop')
- UI.info "Starting up delayed_job..."
- args = "start"
- args << " --min-priority #{@options[:min_priority]}" if @options[:min_priority]
- args << " --max-priority #{@options[:max_priority]}" if @options[:max_priority]
- args << " --number_of_workers=#{@options[:number_of_workers]}" if @options[:number_of_workers]
- args << " --pid-dir=#{@options[:pid_dir]}" if @options[:pid_dir]
- args << " --identifier=#{@options[:identifier]}" if @options[:identifier]
- args << " --monitor" if @options[:monitor]
- args << " --sleep-delay #{@options[:sleep_delay]}" if @options[:sleep_delay]
- args << " --prefix #{@options[:prefix]} " if @options[:prefix]
- system(cmd, args)
- end
-
- # Called on Ctrl-C signal (when Guard quits)
- def stop
- UI.info "Stopping delayed_job..."
- system(cmd, 'stop')
- end
-
- # Called on Ctrl-Z signal
- # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
- def reload
- UI.info "Restarting delayed_job..."
- restart
- end
-
- # Called on Ctrl-/ signal
- # This method should be principally used for long action like running all specs/tests/...
- def run_all
- restart
- end
-
- # Called on file(s) modifications
- def run_on_change(paths)
- restart
- end
-
- private
-
- def restart
- system(cmd, 'restart')
- end
-
- def cmd
- command = "script/delayed_job"
- command = "RAILS_ENV=#{@options[:environment]} #{command}" if @options[:environment]
- command
- end
- end
-end
View
3  lib/guard/delayed/templates/Guardfile
@@ -1,3 +0,0 @@
-guard 'delayed', :environment => 'development' do
- watch(%r{^app/(.+)\.rb})
-end
View
5 lib/guard/delayed/version.rb
@@ -1,5 +0,0 @@
-module Guard
- module DelayedVersion
- VERSION = "0.1.1"
- end
-end
View
83 lib/guard/resque.rb
@@ -0,0 +1,83 @@
+require 'guard'
+require 'guard/guard'
+
+module Guard
+ class Resque < Guard
+
+ # Allowable options are:
+ # :environment e.g. 'test'
+ # :task .e.g 'resque:work'
+ # :queue e.g. '*'
+ # :verbose e.g. true
+ # :trace e.g. true
+ # :stop_signal e.g. KILL
+ def initialize(watchers = [], options = {})
+ @options = options
+ @process = nil
+ @pid = nil
+ @stop_signal = options[:stop_signal] || "TERM"
+ super
+ end
+
+ def start
+ stop
+ UI.info "Starting up resque..."
+ @process = IO.popen(cmd)
+ @pid = @process.pid
+ end
+
+ # Called on Ctrl-C signal (when Guard quits)
+ def stop
+ if @process
+ UI.info("Stopping resque...")
+ ::Process.kill(@stop_signal, @process.pid)
+ ::Process.waitpid(@pid) rescue Errno::ESRCH
+ @process.close
+ @pid = nil
+ UI.info("Stopped process #{@name}")
+ end
+ end
+
+ # Called on Ctrl-Z signal
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
+ def reload
+ UI.info "Restarting resque..."
+ stop
+ start
+ end
+
+ # Called on Ctrl-/ signal
+ # This method should be principally used for long action like running all specs/tests/...
+ def run_all
+ true
+ end
+
+ # Called on file(s) modifications
+ def run_on_change(paths)
+ restart
+ end
+
+ private
+
+ def cmd
+ command = "bundle exec rake "
+
+ # environment setting
+ command << "RAILS_ENV=#{@options[:environment]} " if @options[:environment]
+
+ # queue setting
+ command << "QUEUE=#{@options[:queue] || '*'} "
+
+ # verbose setting
+ command << "VVERBOSE=1 " if @options[:verbose]
+
+ # task setting
+ command << "#{@options[:task] || 'resque:work'} "
+
+ # trace setting
+ command << "--trace " if @options[:trace]
+
+ command
+ end
+ end
+end
View
4 lib/guard/resque/templates/Guardfile
@@ -0,0 +1,4 @@
+guard 'resque', :environment => 'development' do
+ watch(%r{^app/(.+)\.rb})
+ watch(%r{^lib/(.+)\.rb})
+end
View
5 lib/guard/resque/version.rb
@@ -0,0 +1,5 @@
+module Guard
+ module ResqueVersion
+ VERSION = "0.0.1"
+ end
+end
View
8 spec/guard/delayed_spec.rb → spec/guard/resque_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
-describe Guard::Delayed do
- subject { Guard::Delayed.new }
+describe Guard::Resque do
+ subject { Guard::Resque.new }
describe "start" do
before do
- subject = Guard::Delayed.new
+ subject = Guard::Resque.new
end
after do
@@ -14,7 +14,7 @@
it "should create a pid in /tmp/pids" do
subject.start
- Dir.glob("tmp/pids/delayed_job*.pid").should_not be_empty
+ Dir.glob("tmp/pids/resque*.pid").should_not be_empty
end
end
end
View
2  spec/spec_helper.rb
@@ -1,5 +1,5 @@
require 'rspec'
-require 'guard/delayed'
+require 'guard/resque'
ENV["GUARD_ENV"] = 'test'
Please sign in to comment.
Something went wrong with that request. Please try again.