Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set nil as tube_namespace to remove tube prefix #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ NOTE: This is the start of working with @bradgessler to improve backburner and m
## Version 0.1.0 (Nov 4 2012)

* Switch to beaneater as new ruby beanstalkd client
* Add support for array of connections in `beanstalk_url`
* Add support for array of connections in `beanstalk_url`
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ Syntax:

And in case we didn't emphasize it enough: we love tests!

NOTE: Adapted from https://raw.github.com/thoughtbot/factory_girl_rails/master/CONTRIBUTING.md
NOTE: Adapted from https://raw.github.com/thoughtbot/factory_girl_rails/master/CONTRIBUTING.md
6 changes: 3 additions & 3 deletions HOOKS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Backburner Hooks

You can customize Backburner or write plugins using its hook API.
You can customize Backburner or write plugins using its hook API.
In many cases you can use a hook rather than mess around with Backburner's internals.

## Job Hooks
## Job Hooks

Hooks are transparently adapted from [Resque](https://github.com/defunkt/resque/blob/master/docs/HOOKS.md), so
if you are familiar with their hook API, now you can use nearly the same ones with beanstalkd and backburner!
Expand Down Expand Up @@ -45,7 +45,7 @@ class SomeJob
def self.perform(*args)
# ...
end

def self.logger
@_logger ||= Logger.new(STDOUT)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/custom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def self.perform(value, user)
Backburner.enqueue TestJob, 10, 6

# Work tasks using threaded worker
Backburner.work("test-job", :worker => Backburner::Workers::ThreadsOnFork)
Backburner.work("test-job", :worker => Backburner::Workers::ThreadsOnFork)
2 changes: 1 addition & 1 deletion examples/demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def self.foo(x, y)
Backburner.default_queues.concat([Tester::TestJob.queue, Tester::UserModel.queue])
Backburner.work
# Backburner.work("test.job")
# Backburner.work("tester/user-model")
# Backburner.work("tester/user-model")
2 changes: 1 addition & 1 deletion examples/hooked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ def self.foo

# Run work
# Backburner.default_queues << "user"
Backburner.work
Backburner.work
2 changes: 1 addition & 1 deletion examples/retried.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def self.foo(x, y)

# Run work
# Backburner.default_queues << "user"
Backburner.work
Backburner.work
2 changes: 1 addition & 1 deletion examples/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def self.foo(x, y)

# Run work
# Backburner.default_queues << "user"
Backburner.work
Backburner.work
2 changes: 1 addition & 1 deletion examples/stress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def self.perform(value)

# Work tasks using threads_on_fork worker
# twitter tube will have 10 threads, garbage after 1000 executions and retry jobs 1 times.
Backburner.work("test-job:10:100:1", :worker => Backburner::Workers::ThreadsOnFork)
Backburner.work("test-job:10:100:1", :worker => Backburner::Workers::ThreadsOnFork)
2 changes: 1 addition & 1 deletion lib/backburner/async_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def method_missing(method, *args, &block)
::Backburner::Worker.enqueue(@klazz, [@id, method, *args], @opts)
end
end # AsyncProxy
end # Backburner
end # Backburner
9 changes: 7 additions & 2 deletions lib/backburner/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def expand_tube_name(tube)
else # turn into a string
tube.to_s
end
[prefix.gsub(/\.$/, ''), dasherize(queue_name).gsub(/^#{prefix}/, '')].join(".").gsub(/\.+/, '.').split(':').first

if prefix
[prefix.gsub(/\.$/, ''), dasherize(queue_name).gsub(/^#{prefix}/, '')].join(".").gsub(/\.+/, '.').split(':').first
else
dasherize(queue_name).gsub(/^#{prefix}/, '').gsub(/\.+/, '.').split(':').first
end
end

# Resolves job priority based on the value given. Can be integer, a class or nothing
Expand Down Expand Up @@ -135,4 +140,4 @@ def resolve_respond_timeout(ttr)
end

end # Helpers
end # Backburner
end # Backburner
2 changes: 1 addition & 1 deletion lib/backburner/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def find_hook_events(job, event)
end
end
end # Hooks
end # Backburner
end # Backburner
2 changes: 1 addition & 1 deletion lib/backburner/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def logger
Backburner.configuration.logger
end
end
end
end
2 changes: 1 addition & 1 deletion lib/backburner/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
Backburner.work queues, :worker => Backburner::Workers::ThreadsOnFork
end
end # threads_on_fork
end
end
2 changes: 1 addition & 1 deletion lib/backburner/workers/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def start
end
end # Basic
end # Workers
end # Backburner
end # Backburner
2 changes: 1 addition & 1 deletion test/async_proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class AsyncUser; end
job.delete
end
end # method_missing
end # AsyncProxy
end # AsyncProxy
2 changes: 1 addition & 1 deletion test/back_burner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ class TestWorker < Backburner::Worker; end
after do
Backburner.configure { |config| config.default_worker = Backburner::Workers::Simple }
end
end # Backburner
end # Backburner
2 changes: 1 addition & 1 deletion test/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
assert_equal "localhost", @connection.connection.host
end
end # delegator
end # Connection
end # Connection
2 changes: 1 addition & 1 deletion test/fixtures/hooked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ def self.foo(x)
raise HookFailError, "Fail!" if $hooked_fail_count == 1
puts "This is the job running successfully!! #{x.inspect}"
end
end # HookedObjectSuccess
end # HookedObjectSuccess
2 changes: 1 addition & 1 deletion test/fixtures/test_fork_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def self.foo(x, y)
:worker_test_count_set => x * y
}], :queue => 'response'
end
end
end
2 changes: 1 addition & 1 deletion test/fixtures/test_forking_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def self.foo(x, y)
:worker_test_count_set => x * y
}], :queue => 'response'
end
end
end
2 changes: 1 addition & 1 deletion test/fixtures/test_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def self.perform(x, y)
class TestAsyncJob
include Backburner::Performable
def self.foo(x, y); $worker_test_count = x * y; end
end
end
2 changes: 1 addition & 1 deletion test/fixtures/test_queue_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class TestJobSettingsOverride
queue_garbage_limit 1000
queue_retry_limit 2
def self.perform; end
end
end
2 changes: 1 addition & 1 deletion test/helpers/templogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def body
def close
@file.close
end
end
end
14 changes: 14 additions & 0 deletions test/helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
it "supports class names" do
assert_equal "test.foo.job.backburner-jobs", expand_tube_name(RuntimeError)
end # class names

it "removes prefix if configured as nil" do
Backburner.stubs(:configuration).returns(stub(:tube_namespace => nil))

test = stub(:queue => "email/send_news")
assert_equal "email/send-news", expand_tube_name(test)
end

it "removes prefix if configured as false" do
Backburner.stubs(:configuration).returns(stub(:tube_namespace => false))

test = stub(:queue => "email/send_news")
assert_equal "email/send-news", expand_tube_name(test)
end
end # expand_tube_name

describe "for resolve_priority method" do
Expand Down
2 changes: 1 addition & 1 deletion test/performable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def self.bar(state, state2); "baz #{state} #{state2}"; end
assert_equal "baz false true", TestObj.perform(nil, :bar, false, true)
end # class
end # perform
end
end
2 changes: 1 addition & 1 deletion test/queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class TestJobB; include Backburner::Queue; end
assert_equal 300, NestedDemo::TestJobB.queue_respond_timeout
end
end # queue_respond_timeout
end # Backburner::Queue
end # Backburner::Queue
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def clear_jobs!(*tube_names)
Backburner::Worker.connection.tubes.find(expanded_name).clear
end
end
end # MiniTest::Spec
end # MiniTest::Spec
2 changes: 1 addition & 1 deletion test/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
assert_equal ['baz', 'bam'], worker.tube_names
end
end # tube_names
end # Backburner::Worker
end # Backburner::Worker