def ajax_revise_task(): task_name = request.args.get('task_name', '') # must finish = request.args.get("finish", "10") stop_time = request.args.get('stop_time', '') # timestamp user = request.args.get('user', '') #now_ts = datetime2ts("2013-09-06") _id = user + '-' + task_name now_ts = time.time() if stop_time and stop_time < now_ts: return json.dumps([]) if task_name and user: task_detail = es.get(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id)['_source'] if stop_time: task_detail['stop_time'] = stop_time if int(finish) == 0: task_detail['finish'] = finish task_detail['processing_status'] = "1" # 重启时将处理状态改为 if stop_time or int(finish) == 0: es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(['1']) return json.dumps([])
def ajax_stop_task(): task_name = request.args.get('task_name','') # must user = request.args.get('user', '') if task_name and user: _id = user + "-" + task_name task_detail = es.get(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id)['_source'] #task_detail["finish"] = finish_signal task_detail['processing_status'] = '0' es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(['1']) else: return json.dumps([])
def ajax_create_task(): # task_name forbid illegal enter task_number = request.args.get('task_number', 5) task_name = request.args.get('task_name','') # must create_by = request.args.get('create_by', 'admin') # 用户 create_at = str(request.args.get('create_at', int(time.time()))) stop_time = request.args.get('stop_time', "default") #timestamp, 1234567890 keywords = request.args.get("keywords", "") # keywords_list, split with " " remark = request.args.get("remark", "") _id = create_by + "-" + task_name exist_es = es.exists(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id) if exist_es: return json.dumps(["0"]) # 任务名不能重合 query_body = { "query":{ "filtered":{ "filter":{ "bool":{ "must":[ {"term":{"processing_status": "1"}}, {"term":{"finish":"0"}} ] } } } } } unfinish_number = es.count(index=index_manage_sensing_task, doc_type=task_doc_type, body=query_body)['count'] if unfinish_number > (int(task_number)-1): return "more than limit" if task_name: task_detail = dict() task_detail["task_name"] = task_name task_detail["create_by"] = create_by # 创建任务, user task_detail["stop_time"] = stop_time task_detail["remark"] = remark task_detail["create_at"] = create_at task_detail["warning_status"] = '0' task_detail["finish"] = "0" # not end the task task_detail["history_status"] = json.dumps([]) # ts, keywords, warning_status task_detail['burst_reason'] = '' task_detail['processing_status'] = "1" #任务正在进行 task_detail['keywords'] = keywords # store task detail into es es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(["1"])
def ajax_stop_task(): task_name = request.args.get('task_name', '') # must user = request.args.get('user', '') if task_name and user: _id = user + "-" + task_name task_detail = es.get(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id)['_source'] #task_detail["finish"] = finish_signal task_detail['processing_status'] = '0' es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(['1']) else: return json.dumps([])
def ajax_revise_task(): task_name = request.args.get('task_name','') # must finish = request.args.get("finish", "10") stop_time = request.args.get('stop_time', '') # timestamp user = request.args.get('user', '') #now_ts = datetime2ts("2013-09-06") _id = user + '-' + task_name now_ts = time.time() if stop_time and stop_time < now_ts: return json.dumps([]) if task_name and user: task_detail = es.get(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id)['_source'] if stop_time: task_detail['stop_time'] = stop_time if int(finish) == 0: task_detail['finish'] = finish task_detail['processing_status'] = "1" # 重启时将处理状态改为 if stop_time or int(finish) == 0: es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(['1']) return json.dumps([])
def ajax_create_task(): # task_name forbid illegal enter task_number = request.args.get('task_number', 5) task_name = request.args.get('task_name', '') # must create_by = request.args.get('create_by', 'admin') # 用户 create_at = str(request.args.get('create_at', int(time.time()))) stop_time = request.args.get('stop_time', "default") #timestamp, 1234567890 keywords = request.args.get("keywords", "") # keywords_list, split with " " remark = request.args.get("remark", "") _id = create_by + "-" + task_name exist_es = es.exists(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id) if exist_es: return json.dumps(["0"]) # 任务名不能重合 query_body = { "query": { "filtered": { "filter": { "bool": { "must": [{ "term": { "processing_status": "1" } }, { "term": { "finish": "0" } }] } } } } } unfinish_number = es.count(index=index_manage_sensing_task, doc_type=task_doc_type, body=query_body)['count'] if unfinish_number > (int(task_number) - 1): return "more than limit" if task_name: task_detail = dict() task_detail["task_name"] = task_name task_detail["create_by"] = create_by # 创建任务, user task_detail["stop_time"] = stop_time task_detail["remark"] = remark task_detail["create_at"] = create_at task_detail["warning_status"] = '0' task_detail["finish"] = "0" # not end the task task_detail["history_status"] = json.dumps( []) # ts, keywords, warning_status task_detail['burst_reason'] = '' task_detail['processing_status'] = "1" #任务正在进行 task_detail['keywords'] = keywords # store task detail into es es.index(index=index_manage_sensing_task, doc_type=task_doc_type, id=_id, body=task_detail) return json.dumps(["1"])