From b2151521bb19e0571d822e38fce592dc70b940cf Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Tue, 17 Jan 2012 23:45:42 -0700 Subject: [PATCH] add code to cache jobs on the minion if option is set --- salt/config.py | 1 + salt/minion.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/salt/config.py b/salt/config.py index 5863c444ca..641605980f 100644 --- a/salt/config.py +++ b/salt/config.py @@ -80,6 +80,7 @@ def minion_config(path): 'pki_dir': '/etc/salt/pki', 'id': socket.getfqdn(), 'cachedir': '/var/cache/salt', + 'cache_jobs': False, 'conf_file': path, 'renderer': 'yaml_jinja', 'failhard': False, diff --git a/salt/minion.py b/salt/minion.py index 2eca44260c..1257817f6e 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -312,8 +312,21 @@ class Minion(object): except KeyError: pass payload['load'] = self.crypticle.dumps(load) - socket.send(self.serial.dumps(payload)) - return socket.recv() + data = self.serial.dumps(payload) + socket.send(data) + ret = socket.recv() + if self.opts['cache_jobs']: + # Local job cache has been enabled + fn_ = os.path.join( + self.opts['cachedir'], + 'minion_jobs', + load['jid'], + 'return.p') + jdir = os.path.dirname(fn_) + if not os.path.isdir(jdir): + os.makedirs(jdir) + open(fn_, 'w+').write(load) + return ret def authenticate(self): '''