-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove redis gem and resque pool. Upgrade sidekiq (adds redis client). Update redis in docker compose. Modify sidekiq initializer to not use namespaces. * Uncomment * Adds rake task to remove namespaces * Adds comments * Update readme and upgrade redis version in docker compose file * Update readme * Removes old redis migration script
- Loading branch information
Showing
8 changed files
with
28 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,22 @@ | ||
namespace :redis_migrate do | ||
|
||
desc 'Migrate redis db to keys with namespaces identified' | ||
task 'to_namespaces' => :environment do | ||
start = Time.now | ||
graduate_ns = "etda_workflow_graduate:" | ||
honors_ns = "etda_workflow_honors:" | ||
redis = Redis.current | ||
desc 'Migrate redis db to remove namespaces' | ||
task 'remove_namespaces' => :environment do | ||
# This script migrates data from a single namespaced redis | ||
# instance to multiple distinct redis instances for each partner | ||
|
||
schedule_key = redis.keys("schedule") | ||
graduate_schedule_key_contents = [] | ||
honors_schedule_key_contents = [] | ||
old_schedule_key_contents = Hash.new | ||
redis.zscan_each(schedule_key) do |value, score| | ||
old_schedule_key_contents[score] = value | ||
end | ||
# Setup redis connection | ||
redis_config = RedisClient.config(**Rails.application.config_for(:redis)) | ||
redis = redis_config.new_pool(timeout: 0.5, size: 5) | ||
|
||
count = 0 | ||
grad_count = 0 | ||
honors_count = 0 | ||
old_schedule_key_contents.each do |score, value| | ||
if eval(value)[:args][0] > 10000 | ||
graduate_schedule_key_contents << [score, value] | ||
grad_count += 1 | ||
else | ||
honors_schedule_key_contents << [score, value] | ||
honors_count += 1 | ||
end | ||
count += 1 | ||
# Rename all keys including this partner's namespace to the original key with namespace removed | ||
redis.call("KEYS", "etda_workflow_#{current_partner.id}*").each do |key| | ||
redis.call("RENAME", key, key.gsub("etda_workflow_#{current_partner.id}:", '')) | ||
end | ||
|
||
redis.del(schedule_key) | ||
|
||
redis.zadd([graduate_ns, schedule_key].join(""), graduate_schedule_key_contents) | ||
redis.zadd([honors_ns, schedule_key].join(""), honors_schedule_key_contents) | ||
|
||
puts "Process completed in #{(Time.now - start)} sec. #{count} records migrated. #{grad_count} records migrated to graduate namespace. #{honors_count} records migrated to honors namespace." | ||
# Delete all the keys still containing a namespace, hence deleting other partner's keys | ||
redis.call("KEYS", "*").each do |key| | ||
redis.call("DEL", key) if key.include?('etda_workflow') | ||
end | ||
end | ||
end |