def main(): #step1: get task from redis queue (rpop) #step2: get monitor task time record from redis----data: {'monitor_task_time_record':{task_name, compute_start_ts}} #step3: identify the compute_start_ts can be compute #setp4: get task user from es---group_result #step5: according task user count do differently computing #step6: compute task mid-result #step7: save the mid-result in mid-result es----timestamp as field #step8: identify the track task is doing ,not end/delete from group_result es status==1 not 0 #step8: if track_task is doing: update the compute_start_ts #step9: if track_task is doing: lpush task name to redis queue (keep the task in queue) #step10: if track_task is not doing: delete the compute_start_ts from redis while True: task_name = get_task_name() if task_name: start_ts = r_task.hget('monitor_task_time_record', task_name) start_ts = int(start_ts) #now_ts = time.time() #test now_ts = date2ts('2013-09-08 00:15:00') if start_ts == now_ts: status = add_task_name(task_name) if status == 0: print 'add task to redis fail' break if start_ts + 900 <= now_ts: task_user = get_task_user(task_name) if len(task_user) == 1: print 'compute %s start_ts %s' % (task_name, ts2date(start_ts)) #status = compute_mid_result_one(task_name, task_user, start_ts) else: #print 'compute %s start_ts %s' % (task_name, ts2date(start_ts)) #status = compute_mid_result_group(task_name, task_user, start_ts) #compute group polarization----compute once a day if datetime2ts(ts2datetime(start_ts)) == start_ts: print 'start commpute group inner %s' % ts2date( start_ts) group_status = compute_group_inner( task_name, task_user, start_ts) status = group_status #test status = 1 if status == 0: print 'there is a bug about %s task' % task_name else: #update the record time start_ts += 900 task_doing_status = identify_task_doing(task_name) #print 'task_doing_status:', task_doing_status if task_doing_status == True: r_task.hset('monitor_task_time_record', task_name, start_ts) status = add_task_name(task_name) if status == 0: print 'add task name to redis fail' else: r_task.hdel('monitor_task_time_record', task_name)
def main(): #step1: get task from redis queue (rpop) #step2: get monitor task time record from redis----data: {'monitor_task_time_record':{task_name, compute_start_ts}} #step3: identify the compute_start_ts can be compute #setp4: get task user from es---group_result #step5: according task user count do differently computing #step6: compute task mid-result #step7: save the mid-result in mid-result es----timestamp as field #step8: identify the track task is doing ,not end/delete from group_result es status==1 not 0 #step8: if track_task is doing: update the compute_start_ts #step9: if track_task is doing: lpush task name to redis queue (keep the task in queue) #step10: if track_task is not doing: delete the compute_start_ts from redis while True: task_name = get_task_name() if task_name: start_ts = r_task.hget('monitor_task_time_record', task_name) start_ts = int(start_ts) #now_ts = time.time() #test now_ts = date2ts('2013-09-08 00:15:00') if start_ts == now_ts: status = add_task_name(task_name) if status == 0: print 'add task to redis fail' break if start_ts + 900 <= now_ts: task_user = get_task_user(task_name) if len(task_user)==1: print 'compute %s start_ts %s' % (task_name, ts2date(start_ts)) #status = compute_mid_result_one(task_name, task_user, start_ts) else: #print 'compute %s start_ts %s' % (task_name, ts2date(start_ts)) #status = compute_mid_result_group(task_name, task_user, start_ts) #compute group polarization----compute once a day if datetime2ts(ts2datetime(start_ts)) == start_ts: print 'start commpute group inner %s' % ts2date(start_ts) group_status = compute_group_inner(task_name, task_user, start_ts) status = group_status #test status = 1 if status == 0: print 'there is a bug about %s task' % task_name else: #update the record time start_ts += 900 task_doing_status = identify_task_doing(task_name) #print 'task_doing_status:', task_doing_status if task_doing_status == True: r_task.hset('monitor_task_time_record', task_name, start_ts) status = add_task_name(task_name) if status==0: print 'add task name to redis fail' else: r_task.hdel('monitor_task_time_record', task_name)
def add_task_name(task_name): status = r_task.lpush('monitor_task', task_name) return status
def get_task_name(): task_name = '' task_name = r_task.rpop('monitor_task') return task_name