Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rails/solid_queue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1df5a2d212121ff4f0048128da8128c4e460e31b
Choose a base ref
..
head repository: rails/solid_queue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cdd9bf2d4f25a549764229082b3ef714a636dfac
Choose a head ref
Showing with 12 additions and 19 deletions.
  1. +4 −9 README.md
  2. +2 −2 lib/solid_queue/scheduler.rb
  3. +1 −3 lib/solid_queue/worker.rb
  4. +2 −2 test/unit/configuration_test.rb
  5. +3 −3 test/unit/worker_test.rb
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -399,23 +399,18 @@ SolidQueue.on_scheduler_stop
For example:
```ruby
SolidQueue.on_start do |supervisor|
Rails.logger.info "Supervisor #{supervisor.name} started"
MyMetricsReporter.process_name = supervisor.name
start_metrics_server
end
SolidQueue.on_stop do |supervisor|
Rails.logger.info "Supervisor #{supervisor.name} stopped"
SolidQueue.on_stop do |_supervisor|
stop_metrics_server
end
SolidQueue.on_worker_start do |worker|
Rails.logger.info "Worker #{worker.name} started with queues: #{worker.queues.join(',')}"
end
SolidQueue.on_worker_stop do |worker|
Rails.logger.info "Worker #{worker.name} stopped with queues: #{worker.queues.join(',')}"
MyMetricsReporter.process_name = worker.name
MyMetricsReporter.queues = worker.queues.join(',')
end
```

4 changes: 2 additions & 2 deletions lib/solid_queue/scheduler.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ class Scheduler < Processes::Base
include Processes::Runnable
include LifecycleHooks

attr_reader :recurring_schedule

after_boot :run_start_hooks
after_boot :schedule_recurring_tasks
before_shutdown :unschedule_recurring_tasks
@@ -22,8 +24,6 @@ def metadata
end

private
attr_reader :recurring_schedule

SLEEP_INTERVAL = 60 # Right now it doesn't matter, can be set to 1 in the future for dynamic tasks

def run
4 changes: 1 addition & 3 deletions lib/solid_queue/worker.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ class Worker < Processes::Poller
before_shutdown :run_stop_hooks
after_shutdown :run_exit_hooks

attr_reader :queues
attr_reader :queues, :pool

def initialize(**options)
options = options.dup.with_defaults(SolidQueue::Configuration::WORKER_DEFAULTS)
@@ -26,8 +26,6 @@ def metadata
end

private
attr_reader :pool

def poll
claim_executions.then do |executions|
executions.each do |execution|
4 changes: 2 additions & 2 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -135,8 +135,8 @@ def assert_processes(configuration, kind, count, **attributes)
end

def assert_has_recurring_task(scheduler, key:, **attributes)
assert_equal 1, scheduler.instance_variable_get(:@recurring_schedule).configured_tasks.count
task = scheduler.instance_variable_get(:@recurring_schedule).configured_tasks.detect { |t| t.key == key }
assert_equal 1, scheduler.recurring_schedule.configured_tasks.count
task = scheduler.recurring_schedule.configured_tasks.detect { |t| t.key == key }

attributes.each do |attr, value|
assert_equal_value value, task.public_send(attr)
6 changes: 3 additions & 3 deletions test/unit/worker_test.rb
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ class WorkerTest < ActiveSupport::TestCase
@worker.start
wait_for_registered_processes(1, timeout: 1.second)

assert_not @worker.instance_variable_get(:@pool).shutdown?
assert_not @worker.pool.shutdown?

process = SolidQueue::Process.first
assert_equal "Worker", process.kind
@@ -165,8 +165,8 @@ class WorkerTest < ActiveSupport::TestCase

# And now just wait until the worker tries to heartbeat and realises
# it needs to stop
wait_while_with_timeout(2) { !@worker.instance_variable_get(:@pool).shutdown? }
assert @worker.instance_variable_get(:@pool).shutdown?
wait_while_with_timeout(2) { !@worker.pool.shutdown? }
assert @worker.pool.shutdown?
ensure
SolidQueue.process_heartbeat_interval = old_heartbeat_interval
end