X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-replicated;h=8bef0a51d327fdeb18a6f140db908f63818f8759;hb=c181bee3c0c130ebb7b1640573a4e9ba171d2ac8;hp=bb4fa37884f0899f55f7994d2882936bcf5a2795;hpb=3f6b23ba5bdc2a7ce53fdac291bc85843bc8e84f;p=mirror%2Fuserdir-ldap.git diff --git a/ud-replicated b/ud-replicated index bb4fa37..8bef0a5 100755 --- a/ud-replicated +++ b/ud-replicated @@ -25,6 +25,7 @@ from dsa_mq.connection import Connection from dsa_mq.config import Config +import json import logging import logging.handlers import optparse @@ -76,8 +77,17 @@ last_run = 0 def do_replicate(message): global last_run last_update = int(time.time()) - LOG.debug("Got message at %s: %s" % (last_update, message.get('message', message))) - if last_run > message.get('timestamp', last_update): + timestamp = last_update + try: + message = json.loads(message) + except ValueError: + pass + + if isinstance(message, dict): + timestamp = message.get('timestamp', last_update) + message = message.get('message', 'update required') + LOG.debug("Got message at %s: %s" % (last_update, message)) + if last_run > timestamp, last_update): return command = ['/usr/bin/ud-replicate'] @@ -115,5 +125,7 @@ def main(): sys.exit(0) if __name__ == '__main__': - do_replicate('startup complete') + do_replicate(json.dumps( + {'timestamp': time.time(), + 'message': 'startup complete'})) main()