Skip to content

Instantly share code, notes, and snippets.

@naku-i386
Last active January 15, 2019 13:16
Show Gist options
  • Save naku-i386/ffb8b93256273bab537dd8ddbf4f9722 to your computer and use it in GitHub Desktop.
Save naku-i386/ffb8b93256273bab537dd8ddbf4f9722 to your computer and use it in GitHub Desktop.
RubySidekiq - Testing and Clearing
# Control Sidekiq mode in specs
before do
Sidekiq::Testing.disable! # will now actually persist to redis
end
after do
Sidekiq::Testing.fake! # will push to fake jobs array
end
# Retrieve fake jobs
# Tender::AsyncJob::ApplicationExpiry::Worker.jobs.size
#
# Execute fake jobs
# Tender::AsyncJob::ApplicationExpiry::Worker.drain
# Clear sidekiq data between examples
RSpec.configure do |config|
config.before do
# Clear jobs in fake mode
Sidekiq::Worker.clear_all
# Clear real jobs
Sidekiq::RetrySet.new.clear
Sidekiq::ScheduledSet.new.clear
# Clear 'Dead' jobs statistics
Sidekiq::DeadSet.new.clear
# Clear 'Processed' and 'Failed' jobs statistics
Sidekiq::Stats.new.reset
# Clear jobs pushed to queue
Sidekiq::Queue.new.clear
end
end
# Cancel sidekiq job
# Uses linear search so might be very slow if queue is large
job = Sidekiq::ScheduledSet.new.find_job([some_job_record[:jid]])
job.delete if job.present?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment