[英]How to know when a BigQuery job insert is complete
I'm using BigQuery.Jobs.insert to upload a csv blob to a BigQuery table (from a Google Sheets spreadsheet if that matters), but I need to know when the upload is complete so that I can run a query to process it.我正在使用 BigQuery.Jobs.insert 将 csv blob 上传到 BigQuery 表(如果重要的话,从 Google 表格电子表格),但我需要知道上传何时完成,以便我可以运行查询来处理它。 Here's the code I have...
这是我的代码......
csv_blob = Utilities.newBlob(csv,"application/octet-stream");
//Copy the csv to BigQuery
job = BigQuery.Jobs.insert(job, projectId, csv_blob );
var jobId=job.jobReference.jobId;
//Give it a half second to complete
var sleepTimeMs = 500;
Utilities.sleep(sleepTimeMs);
//see if it needs longer
var jobstatus = job.status;
while(jobstatus.state!="COMPLETE") {
Utilities.sleep(sleepTimeMs);
sleepTimeMs *= 2;
jobstatus = job.status;
}
The upload is working, but the job.status.state never changes from "RUNNING", no matter how long I wait.上传工作正常,但 job.status.state 永远不会从“RUNNING”改变,无论我等多久。 Even after I manually verify the uploaded table on the server, the job.status.state is still "RUNNING".
即使在我手动验证服务器上上传的表之后,job.status.state 仍然是“RUNNING”。 What is the right way to know when the job is complete?
知道工作何时完成的正确方法是什么? Thanks
谢谢
You need to fetch the current status of the job with BigQuery.Jobs.Get
( REST reference ), it appears that you're just rechecking the response you received from the initial job insertion.您需要使用
BigQuery.Jobs.Get
( REST 参考)获取作业的当前状态,看来您只是在重新检查从初始作业插入中收到的响应。
An quick and dirty example of invoking this:调用它的一个快速而肮脏的例子:
function myFunction() {
projectID = "my-project-id"
jobID = "some-job-id"
location = "us-central1"
job = BigQuery.Jobs.get(projectID, jobID, {location: location});
console.log("result state: " + job.status.state + " end time:" + job.statistics.endTime);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.