summaryrefslogtreecommitdiffstats
path: root/restful_server/db.py
diff options
context:
space:
mode:
authorzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-08-21 21:40:44 +0800
committerzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-08-23 19:39:38 +0800
commit54dc0d512764ef68b3831bfc59932cf2d9daa187 (patch)
tree3e5fb26ebde438c7f63a8289dd2a688619ff8616 /restful_server/db.py
parente0482d626cedfb1f30712e82df288454af65c76c (diff)
Add some state change functions in db.py.
modification: Add some functions in db.py Unit test will be added after functions called by restful server. Rename 'deadline' to 'max-minutes' JIRA:QTIP-99 Change-Id: I74ed93df3f2dd91fa154fa0fcb52605983ee2719 Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'restful_server/db.py')
-rw-r--r--restful_server/db.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/restful_server/db.py b/restful_server/db.py
index b8314de2..42808b80 100644
--- a/restful_server/db.py
+++ b/restful_server/db.py
@@ -21,7 +21,7 @@ def create_job(args):
'installer_ip': args["installer_ip"],
'pod_name': args["pod_name"],
'suite_name': args["suite_name"],
- 'deadline': args["deadline"],
+ 'max-minutes': args["max-minutes"],
'type': args["type"],
'start-time': str(datetime.now()),
'end-time': None,
@@ -34,7 +34,7 @@ def create_job(args):
def delete_job(job_id):
if job_id in jobs.keys():
- jobs[job_id]['end_time'] = datetime.now()
+ jobs[job_id]['end_time'] = str(datetime.now())
jobs[job_id]['state'] = 'terminated'
return True
else:
@@ -46,3 +46,23 @@ def get_job_info(job_id):
return jobs[job_id]
else:
return None
+
+
+def finish_job(job_id, state):
+ jobs[job_id]['end-time'] = str(datetime.now())
+ jobs[job_id]['state'] = state
+
+
+def update_job_state_detail(job_id, state_detail):
+ jobs[job_id][state_detail] = state_detail
+
+
+def update_job_result(job_id, result):
+ jobs[job_id][result] = result
+
+
+def is_job_timeout(job_id):
+ period = datetime.now() - datetime.strptime(jobs[job_id]['start_time'],
+ "%Y-%m-%d %H:%M:%S.%f")
+ return True if jobs[job_id]['max-minutes'] * 60 < period.total_seconds()\
+ else False