class Task(Resource): """ Show task status """ def __init__(self, redisp=6379): super(Task, self).__init__() self.__redis_connection = redis.Redis(host='redis', port=redisp, db=0) self.__util = TaskUtil() def get(self, job_id): """ GET status of the task. :return: response """ status = self.__redis_connection.hget(name='status', key=job_id) logging.debug('Got status: ' + str(status)) result = { TAG_JOB_ID: job_id, TAG_STATUS: status } return result, 200 def delete(self, job_id): """Delete both job and its result. :return: Success message """ return self.__util.delete_job(job_id), 200
class TaskQueue(Resource): """API for job management. """ def __init__(self, fetch=FETCH_PORT, status=STATUS_PORT, redisp=REDIS_PORT): super(TaskQueue, self).__init__() self.__redis_connection = redis.Redis(host='redis', port=redisp, db=0) self.__util = TaskUtil() def __get_status(self): status_hash = self.__redis_connection.hgetall(name=TAG_STATUS) serializable = [] keys = status_hash.keys() for key in keys: serializable.append( { TAG_JOB_ID: key.decode("utf-8"), TAG_STATUS: status_hash[key].decode("utf-8") } ) return serializable def get(self): status_message = self.__get_status() return status_message, 200 def delete(self): """Delete all jobs :return: """ status_hash = self.__redis_connection.hgetall(name=TAG_STATUS) keys = status_hash.keys() deleted_jobs = [] for key in keys: result = self.__util.delete_job(key) deleted_jobs.append(result[TAG_JOB_ID]) message = { 'deletedJobs': deleted_jobs } return message, 200
class TaskQueue(Resource): """API for job management. """ def __init__(self, fetch=FETCH_PORT, status=STATUS_PORT, redisp=REDIS_PORT): super(TaskQueue, self).__init__() self.__redis_connection = redis.Redis(host='redis', port=redisp, db=0) self.__util = TaskUtil() def __get_status(self): status_hash = self.__redis_connection.hgetall(name=TAG_STATUS) serializable = [] keys = status_hash.keys() for key in keys: serializable.append({ TAG_JOB_ID: key.decode("utf-8"), TAG_STATUS: status_hash[key].decode("utf-8") }) return serializable def get(self): status_message = self.__get_status() return status_message, 200 def delete(self): """Delete all jobs :return: """ status_hash = self.__redis_connection.hgetall(name=TAG_STATUS) keys = status_hash.keys() deleted_jobs = [] for key in keys: result = self.__util.delete_job(key) deleted_jobs.append(result[TAG_JOB_ID]) message = {'deletedJobs': deleted_jobs} return message, 200
class Task(Resource): """ Show task status """ def __init__(self, redisp=6379): super(Task, self).__init__() self.__redis_connection = redis.Redis(host='redis', port=redisp, db=0) self.__util = TaskUtil() def get(self, job_id): """ GET status of the task. :return: response """ status = self.__redis_connection.hget(name='status', key=job_id) logging.debug('Got status: ' + str(status)) result = {TAG_JOB_ID: job_id, TAG_STATUS: status} return result, 200 def delete(self, job_id): """Delete both job and its result. :return: Success message """ return self.__util.delete_job(job_id), 200