def db_set(self, code, data, with_kwargs): """Save the data of a task to the database. Arguments: - code: code of the task. - data: data of the task. - with_kwargs: bool defining it the data has kwargs. If True, the last element of the data is a list with the keys of the kwargs. """ if data: if with_kwargs: names = range(len(data) - 1) names.append(-1) else: names = range(len(data)) data_keys = map(lambda (x): code_output(code, x), names) with self.redis.pipeline() as pipe: while True: try: pipe.watch(data_keys) pipe.multi() [pipe.set(c, d) for c, d in zip(data_keys, data)] res = pipe.execute() if self.display: print('Redis sink: saved data' + str(data_keys) + ' ; ' + str(data)) print(' ' + str(res)) break except WatchError: continue finally: pipe.reset()
def db_set(self, code, data, with_kwargs): """Save the data of a task to the database. Arguments: - code: code of the task. - data: data of the task. - with_kwargs: bool defining it the data has kwargs. If True, the last element of the data is a list with the keys of the kwargs. """ if data: if with_kwargs: names = range(len(data) - 1) names.append(-1) else: names = range(len(data)) data_keys = map(lambda(x): code_output(code, x), names) with self.redis.pipeline() as pipe: while True: try: pipe.watch(data_keys) pipe.multi() [pipe.set(c, d) for c, d in zip(data_keys, data)] res = pipe.execute() if self.display: print('Redis sink: saved data' + str(data_keys) + ' ; ' + str(data)) print(' ' + str(res)) break except WatchError: continue finally: pipe.reset()
def delete(self, server_task, subtask): """Delete the data in the database associated with the server_task and subtask. Publish the message to finish the task.""" if subtask: name_task = code_new_task(server_task, subtask) else: name_task = server_task self.redis_manager.tasks_pub.send(code_finish(name_task)) self.redis_manager.db_delete(map(lambda(x): code_output(name_task, x), range(self.num_output)))
def delete(self, server_task, subtask): """Delete the data in the database associated with the server_task and subtask. Publish the message to finish the task.""" if subtask: name_task = code_new_task(server_task, subtask) else: name_task = server_task self.redis_manager.tasks_pub.send(code_finish(name_task)) self.redis_manager.db_delete( map(lambda (x): code_output(name_task, x), range(self.num_output)))
def finish_task(self): """Get from the database and send to the server the output of the function. Dependencies are send to the redis_manager to be updated.""" self.needed = [code_output(self.code, num) for num in range(self.num_output)] self.ventilator.server.send(self.address, SNDMORE) data = self.wait_exists() if data: self.ventilator.server.send('', SNDMORE) for d in data[:-1]: self.ventilator.server.send(d, SNDMORE) self.ventilator.server.send(data[-1]) else: self.ventilator.server.send('') if self.ventilator.display: print('Send server: ' + str(self.address) + ' ; ' + str(data)) print(str([self.address, data])) self.ventilator.redis_manager.send(self.code)
def db_set(self, data): """Save the data to the database.""" if data: data_keys = [code_output(self.code, i) for i in range(len(data))] with self.ventilator.redis.pipeline() as pipe: while True: try: pipe.watch(data_keys) pipe.multi() [pipe.set(k, d) for k, d in zip(data_keys, data)] res = pipe.execute() if self.ventilator.display: print('Redis vent: saved data' + str(data_keys) + str(data)) print(' ' + str(res)) break except WatchError: continue finally: pipe.reset()
def finish_task(self): """Get from the database and send to the server the output of the function. Dependencies are send to the redis_manager to be updated.""" self.needed = [ code_output(self.code, num) for num in range(self.num_output) ] self.ventilator.server.send(self.address, SNDMORE) data = self.wait_exists() if data: self.ventilator.server.send('', SNDMORE) for d in data[:-1]: self.ventilator.server.send(d, SNDMORE) self.ventilator.server.send(data[-1]) else: self.ventilator.server.send('') if self.ventilator.display: print('Send server: ' + str(self.address) + ' ; ' + str(data)) print(str([self.address, data])) self.ventilator.redis_manager.send(self.code)