1
雲功能有沒有方法確認數據流作業是否成功?確認雲功能中數據流作業的成功
雲功能,我試過:
const google = require('googleapis');
exports.statusJob = function(event, callback) {
const file = event.data;
if (file.resourceState === 'exists' && file.name) {
console.log(file.name);
console.log(event.data);
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
]);
}
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
dataflow.projects.jobs.get({
projectId: 'my-project-id',
resource: {
jobId: 'some_number'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
}
};
包裝JSON:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"googleapis": "^18.0.0"
}
}
以上事情爲我工作完美ONCE。 ,我得到的答覆是:
Dataflow template response: { id: 'some_number', projectId: 'my-project-id', name: 'cloud-fn', type: 'JOB_TYPE_BATCH', environment: { userAgent: { name: 'Google Cloud Dataflow SDK for Java', support: [Object], 'build.date': '2017-05-23 19:46', version: '2.0.0' }, version: { major: '6', job_type: 'JAVA_BATCH_AUTOSCALING' } }, currentState: 'JOB_STATE_DONE',........
然後它那個說法後各一次給了一個錯誤:
problem running dataflow template, error was: Error: Missing required parameters: jobId at createAPIRequest (/user_code/node_modules/googleapis/lib/apirequest.js:110:14) at Object.get (/user_code/node_modules/googleapis/apis/dataflow/v1b3.js:670:16) at /user_code/index.js:22:29 at callback (/user_code/node_modules/googleapis/node_modules/google-auth-library/lib/auth/googleauth.js:42:14) at /user_code/node_modules/googleapis/node_modules/google-auth-library/lib/auth/googleauth.js:289:13 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickDomainCallback (internal/process/next_tick.js:128:9)
有誰知道這事?
感謝
注:一個成功的作業將顯示「Done 「並且失敗的作業將在輸出中顯示狀態字段的」失敗「。 –
好的...如果我想通過JavaScript中的雲功能代碼確認相同的結果怎麼辦? 假設我調用了一個數據流作業,並且在它完成之後我想知道它是否成功...... – rish0097
我假設您通過調用雲功能啓動數據流作業,請按照此處的指導進行操作? https://shinesolutions.com/2017/03/23/triggering-dataflow-pipelines-with-cloud-functions/ 在這個例子中,他們訪問的Javascript googleApis。 您可以編寫另一個調用google API的雲端函數,並調用dataflow.projects.templates.get。不幸的是,我找不到JS API的文檔/代碼示例。但我認爲你可以用projectId和jobId參數來調用它。 –