Exemplo n.º 1
0
def push_job(request):
    if request.method == "POST":
        try:
            vo = ValueObject(json.loads(request.body))
            if not isinstance(vo.type, int):
                vo.type = 0
            if not isinstance(vo.timeout, int):
                vo.timeout = 1
            if not isinstance(vo.time_interval, int):
                vo.time_interval = 1
            if not isinstance(vo.clear, bool):
                vo.clear = False
            job_num = None
            if vo.name is not None and vo.job is not None:
                job_num = MW.push_job(vo.name, vo.job, vo.type, vo.clear)
            result = None
            request_result = False
            if job_num is not None:
                request_result = True
                start_time = time.time()
                response_time = 0.0
                while response_time < vo.timeout:
                    job_finish = MW.get_finish(vo.name, job_num)
                    if job_finish:
                        job_result = MW.get_result(vo.name, job_num)
                        variable = VariableEncoder(MW.get_variable(vo.name),
                                                   encoder_func)
                        result = {
                            "job": job_num,
                            "finish": job_finish,
                            "result": job_result,
                            "time": response_time,
                            "variable": variable
                        }
                        break
                    else:
                        time.sleep(vo.time_interval)
                        response_time = round(time.time() - start_time, 2)
            if result is None:
                result = {
                    "job": job_num,
                    "finish": False,
                    "result": None,
                    "time": vo.timeout,
                    "variable": None
                }
            response_json = {
                "request_result": request_result,
                "result": result
            }
        except Exception as e:
            print(e)
            response_json = {"request_result": False, "result": str(e)}
        return JsonResponse(response_json)
    else:
        return HttpResponse(__RESPONSE_HTTP__)
Exemplo n.º 2
0
def push_job(request):
    if request.method == "POST":
        try:
            vo = ValueObject(json.loads(request.body))
            if not isinstance(vo.type, int):
                vo.type = 0
            if not isinstance(vo.timeout, int):
                vo.timeout = 1
            if not isinstance(vo.time_interval, int):
                vo.time_interval = 1
            if not isinstance(vo.clear, bool):
                vo.clear = False
            job_num = None
            if vo.name is not None and vo.job is not None:
                job_num = MW.push_job(vo.name, vo.job, vo.type, vo.clear)
            result = None
            request_result = False
            if job_num is not None:
                request_result = True
                result = __check_job__(vo.name, job_num, vo.timeout,
                                       vo.time_interval)
                if isinstance(result, dict):
                    result["variable"] = VariableEncoder(
                        MW.get_variable(vo.name), encoder_func)
            if result is None:
                result = {
                    "job": job_num,
                    "finish": False,
                    "result": None,
                    "time": vo.timeout,
                    "variable": None
                }
            response_json = {
                "request_result": request_result,
                "result": result
            }
        except Exception as e:
            print(e)
            response_json = {"request_result": False, "result": str(e)}
        return JsonResponse(response_json)
    else:
        return HttpResponse(__RESPONSE_HTTP__)
Exemplo n.º 3
0
def create_workspace(request):
    if request.method == "POST":
        try:
            vo = ValueObject(json.loads(request.body))
            if not isinstance(vo.type, int):
                vo.type = 0
            if not isinstance(vo.time_interval, int):
                vo.time_interval = 1
            result = MW.create_workspace(vo.name, vo.type, vo.time_interval)
            request_result = result is not None
            response_json = {
                "request_result": request_result,
                "result": result
            }
        except Exception as e:
            print(e)
            response_json = {"request_result": False, "result": str(e)}
        return JsonResponse(response_json)
    else:
        return HttpResponse(__RESPONSE_HTTP__)