def submit_attribute(attribute_name, attribute_value, submit_user, submit_date): status = False #maybe there have to identify the user admitted to submit attribute try: attribute_exist = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['docs'] except: attribute_exist = {} try: source = attribute_exist['_source'] except: input_data = dict() now_ts = time.time() date = ts2datetime(now_ts) input_data['attribute_name'] = attribute_name input_data['attribute_value'] = '&'.join(attribute_value.split(',')) input_data['user'] = submit_user input_data['date'] = submit_date es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=input_data) status = True return status
def end_track_task(task_name): status = 0 try: task_exist = es.get(index=index_name, doc_type=index_type, id=task_name)['_source'] except: return 'task name not exist' task_status = task_exist['status'] if status == '0': return 'task have end' else: task_exist['status'] = 0 # made end time now_ts = time.time() now_date = ts2datetime(now_ts) now_date_ts = datetime2ts(now_date) time_segment = int((now_ts - now_date_ts) / 900) + 1 end_ts = now_date_ts + time_segment * 900 end_date = ts2date(end_ts) task_exist['end_date'] = end_date task_user = task_exist['uid_list'] status = change_user_count(task_user) if status == 0: return 'change user task count fail' else: es.index(index=index_name, doc_type=index_type, id=task_name, body=task_exist) status = delete_task_redis(task_name) if status == 0: return 'delete task from redis fail' else: return 'success change status to end'
def submit_track_task(input_data): ''' step1: identify the task_name is not exist step2: index new task_name step3: add user list to redis---should identify step4: add task to redis queue step5: add start_ts to redis hash----monitor_task_time_record ''' status = 0 task_name = input_data['task_name'] submit_date = input_data['submit_date'] try: result = es.get(index=index_name, doc_type=index_type, id=task_name)['_source'] return 'task_name exist' except: es.index(index=index_name, doc_type=index_type, id=task_name, body=input_data) task_user = input_data['uid_list'] status = add_user_set(task_user) if status == 0: return 'add user to redis set fail' else: status = add_task_redis(task_name) if status == 0: return 'add task to redis fail' else: status = add_task_record_time(task_name, submit_date) if status == 0: return 'add task record time fail' else: return 'success submit'
def end_track_task(task_name): status = 0 try: task_exist = es.get(index=index_name, doc_type=index_type, id=task_name)['_source'] except: return 'task name not exist' task_status = task_exist['status'] if status == '0': return 'task have end' else: task_exist['status'] = 0 # made end time now_ts = time.time() now_date = ts2datetime(now_ts) now_date_ts = datetime2ts(now_date) time_segment = int((now_ts - now_date_ts) / 900) + 1 end_ts = now_date_ts + time_segment * 900 end_date = ts2date(end_ts) task_exist['end_date'] = end_date task_user = task_exist['uid_list'] status = change_user_count(task_user) if status == 0: return 'change user task count fail' else: es.index(index=index_name, doc_type=index_type, id=task_name, body=task_exist) status = delete_task_redis(task_name) if status == 0: return 'delete task from redis fail' else: return 'success change status to end'
def submit_track_task(input_data): ''' step1: identify the task_name is not exist step2: index new task_name step3: add user list to redis---should identify step4: add task to redis queue step5: add start_ts to redis hash----monitor_task_time_record ''' status = 0 task_name = input_data['task_name'] submit_date = input_data['submit_date'] try: result = es.get(index=index_name, doc_type=index_type, id=task_name)['_source'] return 'task_name exist' except: es.index(index=index_name, doc_type=index_type, id=task_name, body=input_data) task_user = input_data['uid_list'] status = add_user_set(task_user) if status == 0: return 'add user to redis set fail' else: status = add_task_redis(task_name) if status == 0: return 'add task to redis fail' else: status = add_task_record_time(task_name, submit_date) if status == 0: return 'add task record time fail' else: return 'success submit'
def submit_task(input_data): status = 0 # mark it can not submit task_name = input_data['task_name'] try: result = es.get(index=index_name, doc_type=index_type, id=task_name) except: status = 1 if status != 0 and 'uid_file' not in input_data: r.lpush('group_task', json.dumps(input_data)) input_data['status'] = 0 # mark the task not compute count = len(input_data['uid_list']) input_data['count'] = count uid_list_string = json.dumps(input_data['uid_list']) es.index(index='group_result', doc_type='group', id=task_name, body=input_data) elif status != 0 and 'uid_file' in input_data: input_data['status'] = 0 # mark the task not compute uid_file = input_data['uid_file'] uid_list = read_uid_file(uid_file) input_data['count'] = len(uid_list) input_data['uid_list'] = json.dumps(uid_list) r.lpush('group_task', json.dumps(input_data)) es.index(index='group_result', doc_type='group', id=task_name, body=input_data) delete_status = delete_uid_file(uid_file) if delete_status == 0: print 'fail delete uid file' elif delete_status == 1: print 'success delete uid file' return status
def submit_task(input_data): status = 0 # mark it can not submit task_name = input_data['task_name'] try: result = es.get(index=index_name, doc_type=index_type, id=task_name) except: status = 1 if status != 0 and 'uid_file' not in input_data: r.lpush('group_task', json.dumps(input_data)) input_data['status'] = 0 # mark the task not compute count = len(input_data['uid_list']) input_data['count'] = count uid_list_string = json.dumps(input_data['uid_list']) es.index(index='group_result', doc_type='group', id=task_name, body=input_data) elif status != 0 and 'uid_file' in input_data: input_data['status'] = 0 # mark the task not compute uid_file = input_data['uid_file'] uid_list = read_uid_file(uid_file) input_data['count'] = len(uid_list) input_data['uid_list'] = json.dumps(uid_list) r.lpush('group_task', json.dumps(input_data)) es.index(index='group_result', doc_type='group', id=task_name, body=input_data) delete_status = delete_uid_file(uid_file) if delete_status == 0: print 'fail delete uid file' elif delete_status == 1: print 'success delete uid file' return status
def delete_attribute_portrait(uid, attribute_name, submit_user): status = False #identify the user exist #identify the attribute value exist in es_user_portrait #identify the submit_user have been admitted---without try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' if attribute_name not in user_exist: return 'user have no attribtue' try: del_attribute_value = user_exist.pop(attribute_name) es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_exist) status = True except Exception, e: raise e
def change_attribute(attribute_name, value, user, state): status = False # identify the attribute_name is in ES - custom attribute try: result = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: result = None return status value_list = '&'.join(value.split(',')) result['attribute_name'] = attribute_name result['attribute_value'] = value_list result['user'] = user now_ts = time.time() now_date = ts2datetime(now_ts) result['date'] = now_date es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name ,body=result) status = True return status
def submit_attribute(attribute_name, attribute_value, submit_user, submit_date): status = False #maybe there have to identify the user admitted to submit attribute try: attribute_exist = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['docs'] except: attribute_exist = {} try: source = attribute_exist['_source'] except: input_data = dict() now_ts = time.time() date = ts2datetime(now_ts) input_data['attribute_name'] = attribute_name input_data['attribute_value'] = '&'.join(attribute_value.split(',')) input_data['user'] = submit_user input_data['date'] = submit_date es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=input_data) status = True return status
def delete_attribute_portrait(uid, attribute_name, submit_user): status = False #identify the user exist #identify the attribute value exist in es_user_portrait #identify the submit_user have been admitted---without try: user_exist = es.get(index=user_index_name, doc_type=user_index_type, id=uid)['_source'] except: return 'no user' if attribute_name not in user_exist: return 'user have no attribtue' try: del_attribute_value = user_exist.pop(attribute_name) es.index(index=user_index_name, doc_type=user_index_type, id=uid, body=user_exist) status = True except Exception, e: raise e
def change_attribute(attribute_name, value, user, state): status = False # identify the attribute_name is in ES - custom attribute try: result = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source'] except: result = None return status value_list = '&'.join(value.split(',')) result['attribute_name'] = attribute_name result['attribute_value'] = value_list result['user'] = user now_ts = time.time() now_date = ts2datetime(now_ts) result['date'] = now_date es.index(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name, body=result) status = True return status