Skip to content

Commit

Permalink
Merge pull request #49 from jandudulski/backburner
Browse files Browse the repository at this point in the history
Add support for Backburner backend
  • Loading branch information
mhfs committed May 1, 2014
2 parents 5e67de2 + aba7c37 commit 0d190ea
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language: ruby
rvm:
- 1.9.3
services:
- redis-server
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Supported backends:
* Delayed::Job
* QueueClassic
* Torquebox
* Backburner

## Installation

Expand Down Expand Up @@ -39,7 +40,7 @@ end
Set your queuing backend by creating `config/initializers/devise_async.rb`:

```ruby
# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox
# Supported options: :resque, :sidekiq, :delayed_job, :queue_classic, :torquebox, :backburner
Devise::Async.backend = :resque
```

Expand Down
1 change: 1 addition & 0 deletions devise-async.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "sidekiq", "~> 1.2"
gem.add_development_dependency "delayed_job_active_record", "~> 0.3"
gem.add_development_dependency "queue_classic", "~> 2.0"
gem.add_development_dependency "backburner", "~> 0.4"
gem.add_development_dependency "mocha", "~> 0.11"
gem.add_development_dependency "minitest", "~> 3.0"
gem.add_development_dependency "torquebox-no-op", "~> 2.3"
Expand Down
1 change: 1 addition & 0 deletions lib/devise/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Async

module Backend
autoload :Base, "devise/async/backend/base"
autoload :Backburner, "devise/async/backend/backburner"
autoload :Resque, "devise/async/backend/resque"
autoload :Sidekiq, "devise/async/backend/sidekiq"
autoload :DelayedJob, "devise/async/backend/delayed_job"
Expand Down
21 changes: 21 additions & 0 deletions lib/devise/async/backend/backburner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Devise
module Async
module Backend
class Backburner < Base

def self.enqueue(*args)
args.unshift(self)
::Backburner.enqueue(*args)
end

def self.perform(*args)
new.perform(*args)
end

def self.queue
Devise::Async.queue
end
end
end
end
end
21 changes: 21 additions & 0 deletions test/devise/async/backend/backburner_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "test_helper"

module Devise
module Async
module Backend
describe "Backburner" do
it "enqueues job" do
::Backburner.expects(:enqueue).with(Backburner, :mailer_method, "User", 123, {})
Backburner.enqueue(:mailer_method, "User", 123, {})
end

it "delegates to devise mailer when delivering" do
user = create_user
ActionMailer::Base.deliveries = []
Backend::Backburner.perform(:confirmation_instructions, "User", user.id, {})
ActionMailer::Base.deliveries.size.must_equal 1
end
end
end
end
end
4 changes: 4 additions & 0 deletions test/devise/async/backend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module Async
Backend.for(:sidekiq).must_equal Backend::Sidekiq
end

it "gives backburner as the backend" do
Backend.for(:backburner).must_equal Backend::Backburner
end

it "gives delayed job as the backend" do
Backend.for(:delayed_job).must_equal Backend::DelayedJob
end
Expand Down
7 changes: 7 additions & 0 deletions test/devise/async/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ module Async
Worker.enqueue(:mailer_method, "User", 123, {})
end

it "enqueues job using the backburner backend" do
Devise::Async.backend = :backburner

Backend::Backburner.expects(:enqueue).with(:mailer_method, "User", 123, {})
Worker.enqueue(:mailer_method, "User", 123, {})
end

it "enqueues job using the delayed job backend" do
Devise::Async.backend = :delayed_job

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require "rails/all"
require "resque"
require "sidekiq"
require "backburner"
require "delayed_job_active_record"
require "sidekiq/testing"
require "torquebox-no-op"
Expand Down

0 comments on commit 0d190ea

Please sign in to comment.