[英]Google Document AI - Inconsistent Long Running Operation's metadata JSON representation
While checking the status of Document AI - Long Running Operation (Form processor), the JSON representation of decodedOperation.metadata
seems to vary during the execution.在检查 Document AI - Long Running Operation (Form processor) 的状态时,
decodedOperation.metadata
的 JSON 表示在执行期间似乎有所不同。 I suspect that operation
response does not resolve straight away despite using then()
on checkBatchProcessDocumentsProgress(operation.name)
.我怀疑尽管在
checkBatchProcessDocumentsProgress(operation.name)
上使用了then()
,但operation
响应并没有立即解决。
This behaviour does not happen using similar code for Google Speech's LROs.使用 Google Speech 的 LRO 的类似代码不会发生此行为。
At console.log
line #24 of implemented code (below), as expected , decodedOperation.metadata
resolves to在
console.log
已实现代码的第 24 行(下方),如预期的那样, decodedOperation.metadata
解析为
{
"state":"RUNNING",
"createTime":{
"seconds":"1669278029",
"nanos":500249000
},
"updateTime":{
"seconds":"1669278029",
"nanos":500249000
}
}
At console.log
line #27, decodedOperation.metadata.state
returns 2
(??)在
console.log
第 27 行, decodedOperation.metadata.state
返回2
(??)
decodedOperation.metadata.state
should return RUNNING
. decodedOperation.metadata.state
应该返回RUNNING
。
More details of output in the code below.下面代码中输出的更多细节。
Environment: node.js 12.02
环境:
node.js 12.02
Package.json:包.json:
{
"dependencies": {
"@google-cloud/documentai": "latest",
}
}
Code:代码:
function run() {
const documentai = require('@google-cloud/documentai').v1;
// Create a promise on object
let options = {
credentials: {
client_email: ** ** ** ,
private_key: ** ** * ,
},
projectId: ** ** *
};
return async (async callback => {
const client = new documentai.DocumentProcessorServiceClient(options);
client.checkBatchProcessDocumentsProgress(properties.operation)
.then(
(decodedOperation) => {
console.log("METADATA " + JSON.stringify(decodedOperation.metadata));
/* logs to console:
{
"state":"RUNNING",
"createTime":{
"seconds":"1669278029",
"nanos":500249000
},
"updateTime":{
"seconds":"1669278029",
"nanos":500249000
}
}
/// then
{
"state":"SUCCEEDED",
"createTime":{
"seconds":"1669278029",
"nanos":500249000
},
"updateTime":{
"seconds":"1669278048",
"nanos":758825000
},
"individualProcessStatuses":[
{
"inputGcsSource":"gs://bucket/intake-form.pdf",
"status":{
},
"outputGcsDestination":"gs://bucket/ocr/7371120297544371692/0",
"humanReviewStatus":{
"state":"SKIPPED",
"stateMessage":"HumanReviewConfig is DISABLED, skipping human review."
}
}
]
}
*/
console.log("STATE " + JSON.stringify(decodedOperation.metadata.state));
/* log to console: 2
when above is "RUNNING" */
/* log to console: 3
when above is "SUCCEEDED" */
if (decodedOperation.metadata.state == "SUCCEEDED") { // Never triggers as decodedOperation.metadata.state evaluates to an integer at this line
};
let response = {
"operationStatus": decodedOperation.metadata.state
};
callback(undefined, response);
})
.catch(
(err) => {
callback(err);
});
})
}
util.inspect(decodedOperation.metadata, { showHidden: false })
returns: util.inspect(decodedOperation.metadata, { showHidden: false })
返回:
BatchProcessMetadata {
{
"individualProcessStatuses":[
"IndividualProcessStatus"{
"inputGcsSource":"gs://bucketxxx/intake-form.pdf",
"status":[
"Status"
],
"outputGcsDestination":"gs://bucketxxx/ocr/7999521463088838887/0",
"humanReviewStatus":[
"HumanReviewStatus"
]
}
],
"state":3,
"createTime":"Timestamp"{
"seconds":"Long"{
"low":1670011754,
"high":0,
"unsigned":false
},
"nanos":105214000
},
"updateTime":"Timestamp"{
"seconds":"Long"{
"low":1670011773,
"high":0,
"unsigned":false
},
"nanos":489028000
}
}
util.inspect(decodedOperation.metadata, { showHidden: true })
returns (section of interest only): util.inspect(decodedOperation.metadata, { showHidden: true })
返回(仅感兴趣的部分):
[...] [root]: [Getter], [fullName]: [Getter] }, State: { STATE_UNSPECIFIED: 0, WAITING: 1, RUNNING: 2, SUCCEEDED: 3, CANCELLING: 4, CANCELLED: 5, FAILED: 6, '0': 'STATE_UNSPECIFIED', '1': 'WAITING', '2': 'RUNNING', '3': 'SUCCEEDED', '4': 'CANCELLING', '5': 'CANCELLED', '6': 'FAILED' }, encode: <ref *5> [Function: BatchProcessMetadata$encode] [...]
To fix this issue, you can access the string representation of the state enum value by using the documentai.v1.BatchProcessMetadata.State object.要解决此问题,您可以使用 documentai.v1.BatchProcessMetadata.State 对象访问状态枚举值的字符串表示形式。 For example:
例如:
console.log("STATE " + documentai.v1.BatchProcessMetadata.State[decodedOperation.metadata.state]);
instead of代替
console.log("STATE " + JSON.stringify(decodedOperation.metadata.state));
Read more about it.阅读更多相关信息。 https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.BatchProcessMetadata.State
https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.BatchProcessMetadata.State
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.