Skip to content

Instantly share code, notes, and snippets.

@avidas
Last active August 30, 2017 19:40
Show Gist options
  • Select an option

  • Save avidas/1e03a4ab83fa0d8a747b9b513ae49fb4 to your computer and use it in GitHub Desktop.

Select an option

Save avidas/1e03a4ab83fa0d8a747b9b513ae49fb4 to your computer and use it in GitHub Desktop.
REVENG-149 Clear Redis variables set for running Sidekiq cron jobs
# JIRA: REVENG-149
# Remove Sidekiq enterprise schedules so late payment notices do not get sent
#
# When Sidekiq enterprise creates a cron job, it sets the keys loop-UNIQUE-ID, loops-UNIQUE-ID
# This keys are not getting cleaned up from Redis when we remove the cron jobs from codebase
# and restart sidekiq and app servers.
require 'sidekiq/api'
begin
# Get sidekiq loop keys from redis
sidekiq_loop_keys = Sidekiq.redis { |conn| conn.keys }.select{ |key| key[/loop-|loops-/] }
Rails.logger.info sidekiq_loop_keys
# Pass the keys for deletion to sidekiq. del will return how many keys got deleted.
result = Sidekiq.redis { |conn| conn.del(*sidekiq_loop_keys) }
# We are expecting to delete 1 or more keys
raise "No Redis keys got deleted" if result < 1
end
@sagross
Copy link

sagross commented Aug 30, 2017

๐Ÿ‘

@jhjwind
Copy link

jhjwind commented Aug 30, 2017

๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment