Commit fa9d9b60 authored by Toon Claes's avatar Toon Claes

Add post-migration to drain all Geo related redis queues

Since gitlab-org/gitlab-ee!2644 is merged, some redis queues are no
longer used. This post-migration drains these queues.

Closes gitlab-org/gitlab-ee#3373.
parent 2b6aa746
---
title: Add post-migration to drain all Geo related redis queues
merge_request: 3289
author:
type: fixed
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class GeoDrainRedisQueues < ActiveRecord::Migration
DOWNTIME = false
GEO_NAMESPACE = 'geo:gitlab'.freeze
disable_ddl_transaction!
def up
Gitlab::Redis::SharedState.with do |redis|
# Delete everything from Geo namespace
matched_keys = redis.scan_each(match: "#{GEO_NAMESPACE}*").to_a
redis.del(*matched_keys) if matched_keys.any?
# Delete the keys related to GeoBulkNotifyWorker (which is removed in gitlab-org/gitlab-ee!2644)
redis.del('resque:gitlab:cron_job:geo_bulk_notify_worker')
redis.del('resque:gitlab:cron_job:geo_bulk_notify_worker:enqueued')
end
end
def down
# noop
end
end
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20171103152048_geo_drain_redis_queues')
describe GeoDrainRedisQueues, :clean_gitlab_redis_shared_state do
subject(:migration) { described_class.new }
def exists_in_redis?(name)
Gitlab::Redis::SharedState.with do |redis|
redis.exists(name)
end
end
def set_in_redis(name, value)
expect(
Gitlab::Redis::SharedState.with do |redis|
redis.set(name, value)
end
).to eq("OK")
end
describe '#up' do
it 'deletes everything in the "geo:gitlab" namespace' do
set_in_redis('geo:gitlab:foo', 'bar')
set_in_redis('bar:gitlab:foo', 'bar')
migration.up
expect(exists_in_redis?('geo:gitlab:foo')).to be_falsy
expect(exists_in_redis?('bar:gitlab:foo')).to be_truthy
end
it 'deletes "resque:gitlab:cron_job:geo_bulk_notify_worker"' do
set_in_redis('resque:gitlab:cron_job:geo_bulk_notify_worker', 'bar')
set_in_redis('resque:gitlab:cron_job:geo_bulk_notify_worker:enqueued', 'bar')
set_in_redis('resque:gitlab:cron_job:other_worker', 'bar')
migration.up
expect(exists_in_redis?('resque:gitlab:cron_job:geo_bulk_notify_worker:enqueued')).to be_falsy
expect(exists_in_redis?('resque:gitlab:cron_job:geo_bulk_notify_worker')).to be_falsy
expect(exists_in_redis?('resque:gitlab:cron_job:other_worker')).to be_truthy
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment