mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Clean up Redis VM objects after redis['data_ttl']
This commit is contained in:
parent
48a9ef0dfd
commit
7b97e58e0f
5 changed files with 47 additions and 3 deletions
|
|
@ -11,7 +11,7 @@ module Vmpooler
|
|||
require 'timeout'
|
||||
require 'yaml'
|
||||
|
||||
%w( api graphite logger pool_manager vsphere_helper ).each do |lib|
|
||||
%w( api graphite janitor logger pool_manager vsphere_helper ).each do |lib|
|
||||
begin
|
||||
require "vmpooler/#{lib}"
|
||||
rescue LoadError
|
||||
|
|
|
|||
39
lib/vmpooler/janitor.rb
Normal file
39
lib/vmpooler/janitor.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
module Vmpooler
|
||||
class Janitor
|
||||
def initialize
|
||||
# Load the configuration file
|
||||
config_file = File.expand_path('vmpooler.yaml')
|
||||
$config = YAML.load_file(config_file)
|
||||
|
||||
# Set some defaults
|
||||
$config[:redis] ||= {}
|
||||
$config[:redis]['server'] ||= 'localhost'
|
||||
$config[:redis]['data_ttl'] ||= 168
|
||||
|
||||
# Load logger library
|
||||
$logger = Vmpooler::Logger.new $config[:config]['logfile']
|
||||
|
||||
# Connect to Redis
|
||||
$redis = Redis.new(host: $config[:redis]['server'])
|
||||
end
|
||||
|
||||
def execute!
|
||||
|
||||
loop do
|
||||
$redis.keys('vmpooler__vm__*').each do |key|
|
||||
data = $redis.hgetall(key);
|
||||
|
||||
if data['destroy']
|
||||
lifetime = (Time.now - Time.parse(data['destroy'])) / 60 / 60
|
||||
|
||||
if lifetime > $config[:redis]['data_ttl']
|
||||
$redis.del(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sleep(600)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,8 +11,8 @@ module Vmpooler
|
|||
$config[:config]['task_limit'] ||= 10
|
||||
$config[:config]['vm_checktime'] ||= 15
|
||||
$config[:config]['vm_lifetime'] ||= 24
|
||||
$config[:redis] ||= {}
|
||||
$config[:redis]['server'] ||= 'localhost'
|
||||
$config[:redis] ||= {}
|
||||
$config[:redis]['server'] ||= 'localhost'
|
||||
|
||||
# Load logger library
|
||||
$logger = Vmpooler::Logger.new $config[:config]['logfile']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue