def listen_loop(): pubsub = r.pubsub() def subscribe(): pubsub.subscribe(PROCESS_CHANNEL) error_mail.redis_func(partial(subscribe), machineinfo) def listen(): return next(pubsub.listen()) while True: msg = error_mail.redis_func(partial(listen), machineinfo) if msg and msg == WORK_MESSAGE: work_loop()
def work_loop(): def pop(): return r.lpop(WORK_QUEUE) while True: job = error_mail.redis_func(partial(pop), machineinfo) if job == None: break job = json.loads(job) datapath = job['path'] host = job['host'] channel = job['hash'] client = SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.load_system_host_keys() client.connect(host) sftp_client = ssh_client.open_sftp() #TODO: Datapath is list sftp_client.get(datapath, TEMP_PATH)