def callback(ch, method, properties, body): stats = "OK" global id procid = id + "-" + misc.generate_id(size=15) file_logger.info(procid + " Start validation: " + repr(body)) dbmeta = logger.file_get(body) file_logger.info(procid + " Database meta data: " + repr(dbmeta)) if dbmeta: base = "/tmp" name = os.path.basename(dbmeta["path"]) fullpath = os.path.join(base, name) try: if os.path.isfile(fullpath): os.remove(fullpath) except OSError: suffix = misc.generate_id() fullpath = fullpath + "-" + suffix trans.download_file(key=dbmeta["path"], name=fullpath) mogmeta = FileInfo("/tmp", name) file_logger.info(procid + " MogileFS meta data: " + repr(mogmeta.to_collection())) if mogmeta.equal_meta(dbmeta): logger.file_validated(dbmeta) else: logger.file_corrupted(dbmeta) migration_job = {"path": dbmeta["path"], "base": dbmeta["base"]} mqclient.send(migration_job) msg = procid + " File corrupted. Sent new job to migration queue: " + json.dumps(dbmeta) logger.warning(msg) stats = "CORRUPTED" os.remove(fullpath) else: if not trans.key_exist(body): file_logger.error("Missing key: " + body) ch.basic_ack(delivery_tag = method.delivery_tag) file_logger.info("%s End validation %s: %s" %(procid, repr(body), stats))