Skip to content

Commit

Permalink
Resque adapter: Support queue pausing only if resque-pause is install…
Browse files Browse the repository at this point in the history
…ed (rails#108)

* support queue pausing only if resque-pause is installed (for the resque adapter)

* update readme

* remove
it from test descriptions
  • Loading branch information
matiassalles99 committed Apr 5, 2024
1 parent 3a826cf commit a64a9d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Besides `base_controller_class`, you can also set the following for `MissionCont
This library extends Active Job with a querying interface and the following setting:
- `config.active_job.default_page_size`: the internal batch size that Active Job will use when sending queries to the underlying adapter and the batch size for the bulk operations defined above—defaults to `1000`.


## Adapter Specifics

- **Resque**: Queue pausing is supported only if you have `resque-pause` installed in your project

## Advanced configuration

When we built Mission Control Jobs, we did it with the idea of managing multiple apps' job backends from a single, centralized app that we used for monitoring, alerts and other tools that related to all our apps. Some of our apps run in more than one datacenter, and we run different Resque instances with different Redis configurations in each. Because of this, we added support for multiple apps and multiple adapters per app. Even when running Mission Control Job within the app it manages, and a single DC, as we migrated from Resque to Solid Queue, we needed to manage both adapters from Mission Control.
Expand Down
4 changes: 4 additions & 0 deletions lib/active_job/queue_adapters/resque_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def find_job(job_id, jobs_relation)
resque_jobs_for(jobs_relation).find_job(job_id)
end

def supports_queue_pausing?
defined?(ResquePauseHelper)
end

private
attr_reader :redis

Expand Down
17 changes: 17 additions & 0 deletions test/active_job/queue_adapters/resque_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
class ActiveJob::QueueAdapters::ResqueTest < ActiveSupport::TestCase
include ActiveJob::QueueAdapters::AdapterTesting

test "supports queue pausing when ResquePauseHelper is defined" do
assert ActiveJob::Base.queue_adapter.supports_queue_pausing?
end

test "does not support queue pausing when ResquePauseHelper is not defined" do
emulating_resque_pause_gem_absence do
assert_not ActiveJob::Base.queue_adapter.supports_queue_pausing?
end
end

private
def emulating_resque_pause_gem_absence
helper_const = Object.send(:remove_const, :ResquePauseHelper)
yield
ensure
Object.const_set(:ResquePauseHelper, helper_const)
end

def queue_adapter
:resque
end
Expand Down

0 comments on commit a64a9d0

Please sign in to comment.