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

Stop using sidekiq #452

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,5 @@ gem 'nokogiri'
gem 'okcomputer'
gem 'parallel'
gem 'racecar', '~> 2.8'
gem 'redis', '~> 5.0'
gem 'redlock'
gem 'rsolr'
gem 'sidekiq', '~> 7.0'
gem 'whenever', require: false # Work around https://github.com/javan/whenever/issues/831
15 changes: 0 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ GEM
config (5.1.0)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
debug (1.9.1)
Expand Down Expand Up @@ -272,12 +271,6 @@ GEM
rake (> 12)
rdoc (6.6.2)
psych (>= 4.0.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.19.1)
connection_pool
redlock (2.0.6)
redis-client (>= 0.14.1, < 1.0.0)
regexp_parser (2.9.0)
reline (0.4.2)
io-console (~> 0.5)
Expand Down Expand Up @@ -334,11 +327,6 @@ GEM
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sidekiq (7.2.0)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.14.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -391,15 +379,12 @@ DEPENDENCIES
puma (~> 5.0)
racecar (~> 2.8)
rails (~> 7.0.0)
redis (~> 5.0)
redlock
rsolr
rspec-rails
rubocop
rubocop-performance
rubocop-rails
rubocop-rspec
sidekiq (~> 7.0)
simplecov
solr_wrapper
tzinfo-data
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Content can be indexed from the Rails console:

```
> druid = 'bb034nj7139' # e.g.
> IndexFullTextContentJob.perform_now(druid)
> IndexFullTextContent.run(druid)
```
You may need to commit this separately

Expand Down
28 changes: 1 addition & 27 deletions app/models/concerns/locking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,7 @@

# Basic lock manager
module Locking
def with_lock(id, &block)
if Rails.application.config.active_job.queue_adapter == :sidekiq
with_redlock(id, &block)
else
with_simple_lock(id, &block)
end
end

private

def with_redlock(id)
Sidekiq.redis_pool.with do |redis|
lock_manager = Redlock::Client.new([redis], { retry_count: 60, retry_delay: 1000 })

# if the lock is available the first try
lock_manager.lock(id, 60000, { extend: { value: SecureRandom.uuid } }) do |locked|
return yield(true) if locked
end

# otherwise, let the lock requestor know that someone else beat them to the punch
lock_manager.lock(id, 60000) do |locked|
yield(false) if locked
end
end
end

def with_simple_lock(id)
def with_lock(id)
lock_file = Rails.root.join('tmp', id)

resp = File.open(lock_file, 'w') do |f|
Expand Down
2 changes: 1 addition & 1 deletion app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def reindex_document
with_lock("indexing_lock_#{id.parameterize}") do |locked_on_first_try|
next if !locked_on_first_try || any_results_for_document?

IndexFullTextContentJob.perform_now(id, commit: true)
IndexFullTextContent.run(id, commit: true)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# frozen_string_literal: true

# Remove content for a druid from the solr index
class GarbageCollectJob < ApplicationJob
def perform
class GarbageCollectIndex
def self.run
response['response']['docs'].each do |doc|
Search.client.delete_by_query("druid:#{doc['druid']}", params: { commit: true })
end
end

private

def response
def self.response
Search.client.get(
Settings.solr.highlight_path,
params: {
Expand All @@ -21,4 +19,5 @@ def response
}
)
end
private_class_method :response
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

# Index full text content into the solr index
class IndexFullTextContentJob < ApplicationJob
def perform(druid, options = { commitWithin: 5000 })
class IndexFullTextContent
def self.run(druid, options = { commitWithin: 5000 })
Search.client.update(
data: {
delete: { query: "druid:#{RSolr.solr_escape(druid)}" },
Expand Down
8 changes: 0 additions & 8 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,3 @@
# Manage racecar via systemd (from dlss-capistrano gem)
set :racecar_systemd_role, :indexer
set :racecar_systemd_use_hooks, true

namespace :deploy do
after :restart, :restart_sidekiq do
on roles(:app) do
sudo :systemctl, "restart", "sidekiq-*", raise_on_non_zero_exit: false
end
end
end
5 changes: 1 addition & 4 deletions config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@

Rails.application.reloader.to_prepare do
OkComputer::Registry.register "solr", OkComputer::HttpCheck.new(Search.client.uri.to_s.sub(/\/$/, '') + '/admin/ping')
end

# Built-in Sidekiq check
OkComputer::Registry.register 'feature-sidekiq', OkComputer::SidekiqLatencyCheck.new('default', 4.hours)
end
3 changes: 0 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
root to: 'search#home'
get '/:id/search', to: 'search#search', as: :iiif_content_search

require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'

mount OkComputer::Engine, at: "/status"
end
2 changes: 1 addition & 1 deletion config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Garbage collect the index
every '15 * * * *' do
runner 'GarbageCollectJob.perform_now'
runner 'GarbageCollectIndex.run'
end
4 changes: 2 additions & 2 deletions spec/models/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
it 'kicks off indexing if no results were found' do
client = instance_double(RSolr::Client, get: { 'response' => { 'numFound' => 0 }, 'highlighting' => {} })
allow(described_class).to receive(:client).and_return(client)
allow(IndexFullTextContentJob).to receive(:perform_now)
allow(IndexFullTextContent).to receive(:run)
search.highlights
expect(IndexFullTextContentJob).to have_received(:perform_now).with('x', commit: true)
expect(IndexFullTextContent).to have_received(:run).with('x', commit: true)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require 'rails_helper'

RSpec.describe IndexFullTextContentJob do
describe '#perform' do
RSpec.describe IndexFullTextContent do
describe '#run' do
it 'adds content to solr' do
allow(Search).to receive(:client).and_return(instance_double(RSolr::Client, update: nil))
allow(PurlObject).to receive(:new).and_return(instance_double(PurlObject, to_solr: [{ id: 1, druid: 'x' }]))
described_class.perform_now('x')
described_class.run('x')
expect(Search.client).to have_received(:update).with(
data: {
delete: { query: 'druid:x' },
Expand Down