Skip to content

Commit

Permalink
Fix Rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
cvhoang committed Dec 26, 2012
1 parent f6eef39 commit b480ef9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Gemfile.lock
doc/
test/dump.rdb
test/dump-cluster.rdb
*.rbc
2 changes: 1 addition & 1 deletion lib/resque/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
task :setup

desc "Start a Resque worker"
task :work => [:pidfile, :setup] do
task :work => [:setup] do
require 'resque'

queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
Expand Down
61 changes: 32 additions & 29 deletions test/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,41 @@
end
end

it "does not raise exception for completed jobs" do
if worker_pid = Kernel.fork
Process.waitpid(worker_pid)
assert_equal 0, Resque::Failure.count
else
# ensure we actually fork
$TESTING = false
Resque.redis.client.reconnect
worker = Resque::Worker.new(:jobs)
worker.work(0)
exit
end
end
if !defined?(RUBY_ENGINE) || defined?(RUBY_ENGINE) && RUBY_ENGINE != "jruby"

it "executes at_exit hooks on exit" do
tmpfile = File.join(Dir.tmpdir, "resque_at_exit_test_file")
FileUtils.rm_f tmpfile

if worker_pid = Kernel.fork
Process.waitpid(worker_pid)
assert File.exist?(tmpfile), "The file '#{tmpfile}' does not exist"
assert_equal "at_exit", File.open(tmpfile).read.strip
else
# ensure we actually fork
$TESTING = false
Resque.redis.client.reconnect
Resque::Job.create(:at_exit_jobs, AtExitJob, tmpfile)
worker = Resque::Worker.new(:at_exit_jobs)
worker.work(0)
exit
it "does not raise exception for completed jobs" do
if worker_pid = Kernel.fork
Process.waitpid(worker_pid)
assert_equal 0, Resque::Failure.count
else
# ensure we actually fork
$TESTING = false
Resque.redis.client.reconnect
worker = Resque::Worker.new(:jobs)
worker.work(0)
exit
end
end

it "executes at_exit hooks on exit" do
tmpfile = File.join(Dir.tmpdir, "resque_at_exit_test_file")
FileUtils.rm_f tmpfile

if worker_pid = Kernel.fork
Process.waitpid(worker_pid)
assert File.exist?(tmpfile), "The file '#{tmpfile}' does not exist"
assert_equal "at_exit", File.open(tmpfile).read.strip
else
# ensure we actually fork
$TESTING = false
Resque.redis.client.reconnect
Resque::Job.create(:at_exit_jobs, AtExitJob, tmpfile)
worker = Resque::Worker.new(:at_exit_jobs)
worker.work(0)
exit
end

end
end

it "fails uncompleted jobs with DirtyExit by default on exit" do
Expand Down

0 comments on commit b480ef9

Please sign in to comment.