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

Some minor fixes and simplifications #499

Merged
merged 7 commits into from
Jan 28, 2025
Merged
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
40 changes: 1 addition & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- 3.1.6
- 3.2.0
- 3.2.4
- 3.3.0
Expand Down Expand Up @@ -64,42 +65,3 @@ jobs:
bin/rails db:setup
- name: Run tests
run: bin/rails test

tests-ruby-3-1-6:
name: Tests Ruby 3.1.6
runs-on: ubuntu-latest
strategy:
matrix:
database: [ mysql, postgres, sqlite ]
services:
mysql:
image: mysql:8.0.31
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- 33060:3306
options: --health-cmd "mysql -h localhost -e \"select now()\"" --health-interval 1s --health-timeout 5s --health-retries 30
postgres:
image: postgres:15.1
env:
POSTGRES_HOST_AUTH_METHOD: "trust"
ports:
- 55432:5432
env:
TARGET_DB: ${{ matrix.database }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Ruby and install specific gems for 3.1.6
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.6
- name: Install dependencies with specific Gemfile.lock
run: |
cp Gemfile.lock.ruby_3_1_6 Gemfile.lock
bundle install
- name: Setup test database
run: |
bin/rails db:setup
- name: Run tests
run: bin/rails test
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ GEM
unicode-display_width (3.1.3)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
zeitwerk (2.7.1)
zeitwerk (2.6.0)

PLATFORMS
arm64-darwin-22
Expand All @@ -199,6 +199,7 @@ DEPENDENCIES
rubocop-rails-omakase
solid_queue!
sqlite3
zeitwerk (= 2.6.0)

BUNDLED WITH
2.5.9
205 changes: 0 additions & 205 deletions Gemfile.lock.ruby_3_1_6

This file was deleted.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ In Solid queue, you can hook into two different points in the supervisor's life:
- `start`: after the supervisor has finished booting and right before it forks workers and dispatchers.
- `stop`: after receiving a signal (`TERM`, `INT` or `QUIT`) and right before starting graceful or immediate shutdown.

And into two different points in a worker's life:
- `worker_start`: after the worker has finished booting and right before it starts the polling loop.
- `worker_stop`: after receiving a signal (`TERM`, `INT` or `QUIT`) and right before starting graceful or immediate shutdown (which is just `exit!`).
And into two different points in the worker's, dispatcher's and scheduler's life:
- `(worker|dispatcher|scheduler)_start`: after the worker/dispatcher/scheduler has finished booting and right before it starts the polling loop or loading the recurring schedule.
- `(worker|dispatcher|scheduler)_stop`: after receiving a signal (`TERM`, `INT` or `QUIT`) and right before starting graceful or immediate shutdown (which is just `exit!`).

You can use the following methods with a block to do this:
```ruby
Expand All @@ -386,6 +386,12 @@ SolidQueue.on_stop

SolidQueue.on_worker_start
SolidQueue.on_worker_stop

SolidQueue.on_dispatcher_start
SolidQueue.on_dispatcher_stop

SolidQueue.on_scheduler_start
SolidQueue.on_scheduler_stop
```

For example:
Expand Down
3 changes: 1 addition & 2 deletions app/models/solid_queue/scheduled_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class << self
def dispatch_next_batch(batch_size)
transaction do
job_ids = next_batch(batch_size).non_blocking_lock.pluck(:job_id)
if job_ids.empty?
0
if job_ids.empty? then 0
else
SolidQueue.instrument(:dispatch_scheduled, batch_size: batch_size) do |payload|
payload[:size] = dispatch_jobs(job_ids)
Expand Down
8 changes: 3 additions & 5 deletions solid_queue.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Gem::Specification.new do |spec|
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "UPGRADING.md"]
end

rails_version = ">= 7.1"
spec.required_ruby_version = '>= 3.1'

rails_version = ">= 7.1"
spec.add_dependency "activerecord", rails_version
spec.add_dependency "activejob", rails_version
spec.add_dependency "railties", rails_version
Expand All @@ -40,8 +41,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rubocop-rails-omakase"
spec.add_development_dependency "rdoc"
spec.add_development_dependency "logger"

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
spec.add_development_dependency "zeitwerk", "2.6.0"
end
spec.add_development_dependency "zeitwerk", "2.6.0"
end
5 changes: 3 additions & 2 deletions test/integration/jobs_lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

class JobsLifecycleTest < ActiveSupport::TestCase
setup do
SolidQueue.on_thread_error = silent_on_thread_error_for([ ExpectedTestError, RaisingJob::DefaultError ])
@_on_thread_error = SolidQueue.on_thread_error
SolidQueue.on_thread_error = silent_on_thread_error_for([ ExpectedTestError, RaisingJob::DefaultError ], @_on_thread_error)
@worker = SolidQueue::Worker.new(queues: "background", threads: 3)
@dispatcher = SolidQueue::Dispatcher.new(batch_size: 10, polling_interval: 0.2)
end

teardown do
SolidQueue.on_thread_error = @on_thread_error
SolidQueue.on_thread_error = @_on_thread_error
@worker.stop
@dispatcher.stop

Expand Down
7 changes: 6 additions & 1 deletion test/integration/processes_lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class ProcessesLifecycleTest < ActiveSupport::TestCase
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: 1.second)

wait_while_with_timeout(1.second) { SolidQueue::ReadyExecution.count > 0 }

signal_process(@pid, :QUIT, wait: 0.4.second)
wait_for_jobs_to_finish_for(2.seconds, except: pause)

Expand Down Expand Up @@ -121,7 +123,9 @@ class ProcessesLifecycleTest < ActiveSupport::TestCase
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: SolidQueue.shutdown_timeout + 10.second)

signal_process(@pid, :TERM, wait: 0.5.second)
wait_while_with_timeout(1.second) { SolidQueue::ReadyExecution.count > 0 }

signal_process(@pid, :TERM, wait: 0.5)

sleep(SolidQueue.shutdown_timeout + 0.5.second)

Expand Down Expand Up @@ -204,6 +208,7 @@ class ProcessesLifecycleTest < ActiveSupport::TestCase

worker = find_processes_registered_as("Worker").first

wait_while_with_timeout(1.second) { SolidQueue::ReadyExecution.count > 0 }
signal_process(worker.pid, :TERM, wait: 0.1.second)

# Worker is gone
Expand Down
2 changes: 1 addition & 1 deletion test/models/solid_queue/process_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SolidQueue::ProcessTest < ActiveSupport::TestCase
worker = SolidQueue::Worker.new(queues: "*", threads: 3, polling_interval: 0.2)
hostname = "Basecamp’s-Computer"

Socket.stub :gethostname, hostname.force_encoding("ASCII-8BIT") do
Socket.stub :gethostname, hostname.dup.force_encoding("ASCII-8BIT") do
worker.start
wait_for_registered_processes(1, timeout: 1.second)

Expand Down
Loading
Loading