Reputation: 131
While checking the status of Document AI - Long Running Operation (Form processor), the JSON representation of decodedOperation.metadata
seems to vary during the execution.
I suspect that operation
response does not resolve straight away despite using then()
on checkBatchProcessDocumentsProgress(operation.name)
.
This behaviour does not happen using similar code for Google Speech's LROs.
At console.log
line #24 of implemented code (below), as expected, decodedOperation.metadata
resolves to
{
"state":"RUNNING",
"createTime":{
"seconds":"1669278029",
"nanos":500249000
},
"updateTime":{
"seconds":"1669278029",
"nanos":500249000
}
}
At console.log
line #27, decodedOperation.metadata.state
returns 2
(!?)
decodedOperation.metadata.state
should return RUNNING
.
More details of output in the code below.
Environment:
node.js 12.02
Package.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:
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):
[...] [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] [...]
Upvotes: 1
Views: 268