make this actually work
[mirror/userdir-ldap.git] / ud-replicated
index 26f8695..1efbcea 100755 (executable)
@@ -71,9 +71,19 @@ formatter = logging.Formatter(SFORMAT)
 syslog_handler.setFormatter(formatter)
 LOG.addHandler(syslog_handler)
 
+last_run = 0
+
 def do_replicate(message):
-    last_update = time.time()
-    LOG.debug("Got message at %s" % last_update)
+    global last_run
+    last_update = int(time.time())
+    timestamp   = last_update
+
+    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']
     if options.dryrun:
@@ -89,7 +99,7 @@ def do_replicate(message):
             LOG.debug('%s finished with ret: 0' % ' '.join(command))
         finally:
             os.environ['TERM'] = old_term
-    LOG.debug(message)
+    last_run = last_update
 
 def main():
     conn = Connection(conf=mq_conf)
@@ -110,5 +120,7 @@ def main():
         sys.exit(0)
 
 if __name__ == '__main__':
-    do_replicate('startup complete')
+    do_replicate(
+        {'timestamp': time.time(),
+        'message': 'startup complete'})
     main()