bin/flapjack-populator in flapjack-0.6.39 vs bin/flapjack-populator in flapjack-0.6.40
- old
+ new
@@ -41,11 +41,11 @@
end.parse!(ARGV)
FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
-config_env = Flapjack::Configuration.new.load(options.config)
+config_env, redis_options = Flapjack::Configuration.new.load(options.config)
if config_env.nil? || config_env.empty?
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
exit(false)
end
@@ -53,22 +53,16 @@
if options.from
filename = options.from
file = File.new(filename)
end
-def get_redis_connection(cfg)
- opts = cfg['path'] ? {:path => cfg['path']} :
- {:host => cfg['host'], :port => cfg['port']}
- Redis.new(opts.merge(:db => cfg['db']))
-end
-
case command
when "import-contacts"
contacts = JSON.parse(file)
if contacts && contacts.is_a?(Enumerable) && contacts.any? {|e| !e['id'].nil?}
- @persistence = get_redis_connection(config_env['redis'])
+ @persistence = Redis.new(redis_options)
@persistence.multi do
contacts.each do |contact|
unless contact['id']
puts "Contact not imported as it has no id: " + contact.inspect
next
@@ -81,11 +75,11 @@
when "import-entities"
entities = JSON.parse(file)
if entities && entities.is_a?(Enumerable) && entities.any? {|e| !e['id'].nil?}
- @persistence = get_redis_connection(config_env['redis'])
+ @persistence = Redis.new(redis_options)
@persistence.multi
entities.each do |entity|
unless entity['id']
puts "Entity not imported as it has no id: " + entity.inspect
next
@@ -95,11 +89,17 @@
@persistence.exec
@persistence.quit
end
when "purge-events"
- @persistence = get_redis_connection(config_env['redis'])
- Flapjack::Data::Event.purge_all(:redis => @persistence)
+ @persistence = Redis.new(redis_options)
+ events_size = @persistence.llen('events')
+ puts "purging #{events_size} events..."
+ etq = "events.#{Time.now.to_i}"
+ puts "renaming 'events' to '#{etq}'"
+ @persistence.rename('events', etq)
+ puts "setting expiry of '#{etq}' to 8 hours"
+ @persistence.expire(etq, (60 * 60 * 8))
@persistence.quit
else
puts "you need to give me something to do, eg a command like 'import-entities' or 'import-clients' etc"
raise ArgumentError