Skip to content

Commit

Permalink
A VPollerWorker instance now can take advantage of using an expiring
Browse files Browse the repository at this point in the history
cache for managed objects
  • Loading branch information
dnaeon committed Jan 30, 2015
1 parent 9b77845 commit fdf155c
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def __init__(self, config_file, num_workers=0):
'proxy': 'tcp://localhost:10123',
'helpers': None,
'tasks': None,
'cache_enabled': False,
'cache_ttl': 3600,
}

def start(self):
Expand Down Expand Up @@ -141,7 +143,9 @@ def load_config(self):
self.config['proxy'] = parser.get('worker', 'proxy')
self.config['helpers'] = parser.get('worker', 'helpers')
self.config['tasks'] = parser.get('worker', 'tasks')

self.config['cache_ttl'] = parser.getint('cache', 'ttl')
self.config['cache_enabled'] = parser.getboolean('cache', 'enabled')

if self.config['helpers']:
self.config['helpers'] = self.config['helpers'].split(',')

Expand Down Expand Up @@ -173,7 +177,9 @@ def start_workers(self):
db=self.config.get('db'),
proxy=self.config.get('proxy'),
helpers=self.config.get('helpers'),
tasks=self.config.get('tasks')
tasks=self.config.get('tasks'),
cache_enabled=self.config.get('cache_enabled'),
cache_ttl=self.config.get('cache_ttl')
)
worker.daemon = True
self.workers.append(worker)
Expand Down Expand Up @@ -301,16 +307,20 @@ class VPollerWorker(multiprocessing.Process):
run() method
"""
def __init__(self, db, proxy, helpers, tasks):
def __init__(self, db, proxy, helpers, tasks, cache_enabled, cache_ttl):
"""
Initialize a new VPollerWorker object
Args:
db (str): Path to the vConnector database file
proxy (str): Endpoint to which vPoller Workers connect
and receive new tasks for processing
helpers (list): A list of helper modules to be loaded
task (list): A list of task modules to be loaded
db (str): Path to the vConnector database file
proxy (str): Endpoint to which vPoller Workers connect
and receive new tasks for processing
helpers (list): A list of helper modules to be loaded
task (list): A list of task modules to be loaded
cache_enabled (bool): If True use an expiring cache for the
managed objects
cache_ttl (int): Time in seconds after which a cached
object is considered as expired
"""
super(VPollerWorker, self).__init__()
Expand All @@ -319,6 +329,8 @@ def __init__(self, db, proxy, helpers, tasks):
'proxy': proxy,
'helpers': helpers,
'tasks': tasks,
'cache_ttl': cache_ttl,
'cache_enabled': cache_enabled,
}
self.task_modules = {}
self.helper_modules = {}
Expand Down Expand Up @@ -565,7 +577,9 @@ def create_agents(self):
a = VConnector(
user=agent['user'],
pwd=agent['pwd'],
host=agent['host']
host=agent['host'],
cache_enabled=self.config.get('cache_enabled'),
cache_ttl=self.config.get('cache_ttl')
)
self.agents[a.host] = a
logger.info('Created vSphere Agent for %s', agent['host'])
Expand Down

0 comments on commit fdf155c

Please sign in to comment.