045 online status check for operation restart

This commit is contained in:
msyu
2025-01-31 09:56:46 +03:00
parent c025dc5bba
commit 16c9cc0a0e
2 changed files with 45 additions and 6 deletions
+2 -1
View File
@@ -51,7 +51,7 @@
//variables.framework.docs={}; //variables.framework.docs={};
variables.framework.docs.APIName="Deck API"; variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.044"; variables.framework.docs.APIVersion="0.045";
variables.framework.globalHeaders = structNew(); variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location"; variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
@@ -156,6 +156,7 @@
//if (UCase(arguments.verb) EQ 'OPTIONS') return newRepresentation().noData().withStatus("204","No Data").withHeaders({"Content-Type":"application/json;charset=utf-8"}); //if (UCase(arguments.verb) EQ 'OPTIONS') return newRepresentation().noData().withStatus("204","No Data").withHeaders({"Content-Type":"application/json;charset=utf-8"});
if (uCase(arguments.verb) EQ 'OPTIONS') return true; if (uCase(arguments.verb) EQ 'OPTIONS') return true;
if (lCase(arguments.cfc) EQ 'err') return true; if (lCase(arguments.cfc) EQ 'err') return true;
if (lCase(arguments.cfc) EQ 'throw') return true;
var auth=""; var auth="";
if (structKeyExists(headers,"Authorization")) { if (structKeyExists(headers,"Authorization")) {
+43 -5
View File
@@ -33,17 +33,27 @@
<!--- Check operation status, do not start already started (*** consider timeout and cancelling timed out operations here) ---> <!--- Check operation status, do not start already started (*** consider timeout and cancelling timed out operations here) --->
<cfquery name="local.qCheckStarted" result="local.result"> <cfquery name="local.qCheckStarted" result="local.result">
select io.dt_submit, io.dt_finish, io.submit_result select io.dt_submit, io.dt_finish, io.dt_start, io.submit_result, io.status_url
from instance_operation io from instance_operation io
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/> where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/>
</cfquery> <!--- <cfdump var=#local.qCheckStarted.dt_finish#/><cfabort/> ---> </cfquery> <!--- <cfdump var=#local.qCheckStarted.dt_finish#/><cfabort/> --->
<cfif local.qCheckStarted.recordCount EQ 0>
<!---
попытаемся проверить, не упала ли операция раньше времени
при этом стараемся исключить эффект дребезга - если мы пошлем две команды на выполнение одну за другой, вторая не должна запуститься
перезапуск операции разрешен, если она зафейлилась либо явно (оркестратор ее пометил таковой) или неявно (джоб упал, не успев отметить операцию стартовавшей)
Возможно, эту логику нужно воспроизвести на фронте
--->
<cfif local.qCheckStarted.recordCount EQ 0>
<cfreturn representationOf(this.helper.formatMessage("There is no configured instance operation with uid #arguments.instanceOperationUid#","Instance operation not found")).withStatus(404)/> <cfreturn representationOf(this.helper.formatMessage("There is no configured instance operation with uid #arguments.instanceOperationUid#","Instance operation not found")).withStatus(404)/>
<cfelseif left(local.qCheckStarted.submit_result,1) EQ "2" AND len(local.qCheckStarted.dt_finish) EQ 0><!--- 201 etc ---> <cfelseif left(local.qCheckStarted.submit_result,1) EQ "2" AND len(local.qCheckStarted.dt_finish) EQ 0><!--- 201 etc --->
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/> <cfif getJobStatus(local.qCheckStarted.status_url) NEQ 'FAILED'>
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/>
</cfif>
</cfif> </cfif>
<!--- Check CFS parameters at least for existence <!--- Check CFS parameters at least for existence
(*** would be better to check RFS but now CFS params are primary, RFS even mostly do not have is_required flag set) ---> (*** would be better to check RFS but now CFS params are primary, RFS even mostly do not have is_required flag set) --->
<!--- *** !!! тут возможна ошибка из-за нечеткого понимания: даже в отсутствие обязательного CFS параметра RFS параметр может быть сгенерирован, например, из дефолта. То есть данный вариант проверки - неполный и ущербный, впоследствии может неожиданно перестать работать ---> <!--- *** !!! тут возможна ошибка из-за нечеткого понимания: даже в отсутствие обязательного CFS параметра RFS параметр может быть сгенерирован, например, из дефолта. То есть данный вариант проверки - неполный и ущербный, впоследствии может неожиданно перестать работать --->
<cfquery name="local.qCheckCfsParams" result="local.result"> <cfquery name="local.qCheckCfsParams" result="local.result">
@@ -262,5 +272,33 @@
</cfquery> </cfquery>
<!--- <cfdump var=#ARGUMENTS#/> ---> <!--- <cfdump var=#ARGUMENTS#/> --->
</cffunction> </cffunction>
<cffunction name="getJobStatus">
<cfargument name="status_url">
<cftry>
<cfhttp method="get"
url="#arguments.status_url#"
timeout="3"
charset="utf-8"
result="local.jobStatus"
>
<cfhttpparam type="HEADER" name="Authorization" value="#request.ORCHESTRATOR_AUTH#">
<cfhttpparam type="HEADER" name="Accept" value="application/json">
</cfhttp>
<cftry>
<cfset var jobStatusData=#deserializeJson(local.jobStatus.filecontent)#/>
<cfreturn jobStatusData.result/>
<cfcatch type="any">
<cfreturn "cannot obtain job result"/><!--- можно было бы и поаккуратнее - проверить код ответа, потом проверить наличие поля --->
<!--- <cfthrow message="ERROR #cfcatch.message#" detail="#cfcatch.detail#"/> --->
</cfcatch>
</cftry>
<cfcatch type="any">
<cfthrow message="Cannot connect to the orchestrator. #cfcatch.message#" detail="#cfcatch.detail#"/>
</cfcatch>
</cftry>
</cffunction>
</cfcomponent> </cfcomponent>