Skip to content

Commit

Permalink
remove sidekiq-unique-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed May 27, 2024
1 parent 2f81a8d commit 8f2dc2d
Show file tree
Hide file tree
Showing 36 changed files with 16 additions and 183 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ gem 'rails-pattern_matching'

# Background jobs
gem 'sidekiq', '~> 7.2.4'
gem 'sidekiq-unique-jobs', '~> 8.0.10'
gem 'sidekiq-cron', '~> 1.12.0'
gem 'sidekiq-cronitor', '~> 3.6.0'

Expand Down
5 changes: 0 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,6 @@ GEM
sidekiq-cronitor (3.6.0)
cronitor (~> 5.0)
sidekiq (< 8)
sidekiq-unique-jobs (8.0.10)
concurrent-ruby (~> 1.0, >= 1.0.5)
sidekiq (>= 7.0.0, < 8.0.0)
thor (>= 1.0, < 3.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -571,7 +567,6 @@ DEPENDENCIES
sidekiq (~> 7.2.4)
sidekiq-cron (~> 1.12.0)
sidekiq-cronitor (~> 3.6.0)
sidekiq-unique-jobs (~> 8.0.10)
sprockets (~> 3.0)
stackprof
stripe (~> 5.43)
Expand Down
3 changes: 1 addition & 2 deletions app/workers/create_webhook_events_worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class CreateWebhookEventsWorker < BaseWorker
sidekiq_options queue: :webhooks,
lock: :until_executed
sidekiq_options queue: :webhooks

def perform(event, account_id, payload, environment_id = nil)
account = Rails.cache.fetch(Account.cache_key(account_id), skip_nil: true, expires_in: 15.minutes) do
Expand Down
1 change: 0 additions & 1 deletion app/workers/cull_dead_machines_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class CullDeadMachinesWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed, lock_ttl: 10.minutes, on_conflict: :raise,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/cull_dead_processes_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class CullDeadProcessesWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed, lock_ttl: 10.minutes, on_conflict: :raise,
cronitor_disabled: false

def perform
Expand Down
3 changes: 1 addition & 2 deletions app/workers/event_log_worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class EventLogWorker < BaseWorker
sidekiq_options lock: :until_executed,
queue: :logs
sidekiq_options queue: :logs

def perform(
event,
Expand Down
3 changes: 1 addition & 2 deletions app/workers/event_notification_worker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class EventNotificationWorker < BaseWorker
sidekiq_options lock: :until_executed,
queue: :logs
sidekiq_options queue: :logs

def perform(
event,
Expand Down
1 change: 0 additions & 1 deletion app/workers/license_expirations_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class LicenseExpirationsWorker < BaseWorker
sidekiq_options queue: :critical,
lock: :until_executed, lock_ttl: 30.minutes, on_conflict: :raise,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/license_overdue_check_ins_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class LicenseOverdueCheckInsWorker < BaseWorker
sidekiq_options queue: :critical,
lock: :until_executed, lock_ttl: 30.minutes, on_conflict: :raise,
cronitor_disabled: false

def perform
Expand Down
7 changes: 1 addition & 6 deletions app/workers/machine_heartbeat_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

class MachineHeartbeatWorker < BaseWorker
sidekiq_options queue: :critical,
retry: 1_000_000, # retry forever
lock: :until_executing,
on_conflict: {
client: :replace,
server: :raise,
}
retry: 1_000_000 # retry forever

sidekiq_retry_in { |count|
if count in 0..60
Expand Down
7 changes: 1 addition & 6 deletions app/workers/process_heartbeat_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

class ProcessHeartbeatWorker < BaseWorker
sidekiq_options queue: :critical,
retry: 1_000_000, # retry forever
lock: :until_executing,
on_conflict: {
client: :replace,
server: :raise,
}
retry: 1_000_000 # retry forever

sidekiq_retry_in { |count|
if count in 0..60
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_event_logs_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PruneEventLogsWorker < BaseWorker
].freeze

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_expired_tokens_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class PruneExpiredTokensWorker < BaseWorker
BATCH_WAIT = ENV.fetch('KEYGEN_PRUNE_BATCH_WAIT') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_metrics_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class PruneMetricsWorker < BaseWorker
BATCH_WAIT = ENV.fetch('KEYGEN_PRUNE_BATCH_WAIT') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_release_download_links_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class PruneReleaseDownloadLinksWorker < BaseWorker
BATCH_WAIT = ENV.fetch('KEYGEN_PRUNE_BATCH_WAIT') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_release_upgrade_links_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class PruneReleaseUpgradeLinksWorker < BaseWorker
BATCH_WAIT = ENV.fetch('KEYGEN_PRUNE_BATCH_WAIT') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_request_logs_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class PruneRequestLogsWorker < BaseWorker
BATCH_WAIT = ENV.fetch('KEYGEN_PRUNE_BATCH_WAIT') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/prune_webhook_events_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class PruneWebhookEventsWorker < BaseWorker
SLEEP_DURATION = ENV.fetch('PRUNE_SLEEP_DURATION') { 1 }.to_f

sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/request_limits_report_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class RequestLimitsReportWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
7 changes: 1 addition & 6 deletions app/workers/touch_license_worker.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# frozen_string_literal: true

class TouchLicenseWorker < BaseWorker
sidekiq_options retry: false,
lock: :until_executing,
on_conflict: {
client: :replace,
server: :raise,
}
sidekiq_options retry: false

def perform(license_id, touches)
license = License.find(license_id)
Expand Down
1 change: 0 additions & 1 deletion app/workers/vacuum_analyze_event_logs_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class VacuumAnalyzeEventLogsWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/vacuum_analyze_metrics_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class VacuumAnalyzeMetricsWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/vacuum_analyze_request_logs_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class VacuumAnalyzeRequestLogsWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/vacuum_analyze_webhook_events_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class VacuumAnalyzeWebhookEventsWorker < BaseWorker
sidekiq_options queue: :cron,
lock: :until_executed,
cronitor_disabled: false

def perform
Expand Down
1 change: 0 additions & 1 deletion app/workers/webhook_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class WebhookWorker < BaseWorker

sidekiq_options queue: :webhooks,
retry: 15,
lock: :until_executed,
dead: false

sidekiq_retry_in do |count|
Expand Down
17 changes: 0 additions & 17 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'sidekiq'
require 'sidekiq-unique-jobs'
require 'sidekiq-cron'
require 'sidekiq/web'

Expand Down Expand Up @@ -37,10 +36,6 @@
write_timeout: ENV.fetch('REDIS_WRITE_TIMEOUT') { 5 }.to_i,
read_timeout: ENV.fetch('REDIS_READ_TIMEOUT') { 5 }.to_i,
}

config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
end

# Configure Sidekiq server
Expand All @@ -53,23 +48,11 @@
network_timeout: 5,
}

config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end

config.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
unless ENV.key?('NO_CRONITOR')
chain.add Sidekiq::Cronitor::ServerMiddleware
end
end

SidekiqUniqueJobs::Server.configure(config)
end

# Configure Sidekiq unique jobs
SidekiqUniqueJobs.configure do |config|
config.enabled = !Rails.env.test?
end

# Enable strict args for development/test
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'sidekiq/web'
require 'sidekiq_unique_jobs/web'

Rails.application.routes.draw do
domain_constraints = {
Expand Down
10 changes: 2 additions & 8 deletions spec/workers/cull_dead_machines_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
let(:worker) { CullDeadMachinesWorker }
let(:account) { create(:account) }

# See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing
before do
Sidekiq::Testing.inline!
end

after do
Sidekiq::Worker.clear_all
end
before { Sidekiq::Testing.inline! }
after { Sidekiq::Testing.fake! }

context 'without a monitor' do
let(:heartbeat_jid) { nil }
Expand Down
10 changes: 2 additions & 8 deletions spec/workers/cull_dead_processes_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
let(:worker) { CullDeadProcessesWorker }
let(:account) { create(:account) }

# See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing
before do
Sidekiq::Testing.inline!
end

after do
Sidekiq::Worker.clear_all
end
before { Sidekiq::Testing.inline! }
after { Sidekiq::Testing.fake! }

context 'without a monitor' do
let(:heartbeat_jid) { nil }
Expand Down
8 changes: 0 additions & 8 deletions spec/workers/license_expirations_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
let(:worker) { LicenseExpirationsWorker }
let(:account) { create(:account) }

it 'should enqueue and run the worker' do
worker.perform_async
expect(worker.jobs.size).to eq 1

worker.drain
expect(worker.jobs.size).to eq 0
end

context 'when there is a license that has recently expired' do
let(:event) { 'license.expired' }

Expand Down
8 changes: 0 additions & 8 deletions spec/workers/license_overdue_check_ins_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
let(:worker) { LicenseOverdueCheckInsWorker }
let(:account) { create(:account) }

it 'should enqueue and run the worker' do
worker.perform_async
expect(worker.jobs.size).to eq 1

worker.drain
expect(worker.jobs.size).to eq 0
end

context 'when there is a license that has recently become overdue' do
let(:event) { 'license.check-in-overdue' }

Expand Down
31 changes: 0 additions & 31 deletions spec/workers/machine_heartbeat_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@
let(:worker) { MachineHeartbeatWorker }
let(:account) { create(:account) }

# See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing
before do
SidekiqUniqueJobs.configure { _1.enabled = true }
end

after do
SidekiqUniqueJobs.configure { _1.enabled = false }
end

it 'should enqueue and run the worker' do
machine = create :machine, last_heartbeat_at: nil, account: account

worker.perform_async machine.id
expect(worker.jobs.size).to eq 1

worker.drain
expect(worker.jobs.size).to eq 0
end

it 'should replace the worker on conflict' do
machine = create :machine, last_heartbeat_at: nil, account: account

worker.perform_async machine.id
worker.perform_async machine.id
worker.perform_async machine.id
expect(worker.jobs.size).to eq 1

worker.drain
expect(worker.jobs.size).to eq 0
end

context 'when there is a machine that does not require heartbeats' do
let(:machine) { create(:machine, last_heartbeat_at: heartbeat_at, account: account) }
let(:event) { 'machine.heartbeat.pong' }
Expand Down
Loading

0 comments on commit 8f2dc2d

Please sign in to comment.