예제 #1
0
파일: runner.py 프로젝트: wendal/vTest
def start_task(record, robot_conf, db_info):
    start_time = time.time()
    
    try :
        err = 0
        dura = ''
        step = 0
        msg = None
        
        task_d = json.loads(record['detail'])
        
        h = BaseHandler(task_d, robot_conf)
        from vtest.client.handlers import SUCCESS, FAIL
        try :
            result = h.run()
            if result == SUCCESS :
                err = 0
            elif result == FAIL :
                err = 1
            else :
                err = 2
            dura = ','.join([str(t) for t in h.nodes_report['times']])
            if err :
                step = h.nodes_report['step']
                msg = h.last_msg
        except :
            log.error('Fail to start new task', exc_info=1)
        time_used = (time.time() - start_time) * 1000
        log.info('Time use = %dms' % time_used)
        conn = None
        try :
            conn, cur = DB.connect(db_info)
            cur.execute('''insert into t_task_re(rid,tid,lm,err,step,msg,total,dura) values(%d,%d,now(),%d,%d,'%s',%d,'%s')''' % 
                        (robot_conf['rid'], record['id'], err, step, msg, time_used, dura))
            if err == 0 :
                cur.execute('''update t_task set done=done+1 , nok=nok+1 where id=%d''' % record['id'])
            else :
                cur.execute('''update t_task set done=done+1 , nfail=nfail+1 where id=%d''' % record['id'])
            cur.execute('''update t_task set stat=2 where done >= fnn''')
            conn.commit()
            log.info('Task done and update t_task_re success')
        except :
            log.error('Fail to update task status?!!', exc_info=1)
        finally:
            DB.close(conn)
    except :
        raise
        log.error('Fail to execute task?!!', exc_info=1)
예제 #2
0
 def test_upload(self):
     with open('meta/upload_img.json') as f :
         h2 = BaseHandler(json.load(f), {'rid' : -1})
         assert SUCCESS == h2.run()