Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return bq job id from biquery.run_job() #2957

Merged
merged 6 commits into from
Jun 8, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions luigi/contrib/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ def run_job(self, project_id, body, dataset=None):
status = self.client.jobs().get(projectId=project_id, jobId=job_id).execute(num_retries=10)
if status['status']['state'] == 'DONE':
if status['status'].get('errorResult'):
raise Exception('BigQuery job failed: {}'.format(status['status']['errorResult']))
return
raise BigQueryExecutionError(job_id, status['status']['errorResult'])
return job_id
tomasaschan marked this conversation as resolved.
Show resolved Hide resolved

logger.info('Waiting for job %s:%s to complete...', project_id, job_id)
time.sleep(5)
Expand Down Expand Up @@ -786,3 +786,10 @@ def run(self):
BigqueryRunQueryTask = BigQueryRunQueryTask
BigqueryCreateViewTask = BigQueryCreateViewTask
ExternalBigqueryTask = ExternalBigQueryTask


class BigQueryExecutionError(Exception):
def __init__(self, job_id, error_message) -> None:
tomasaschan marked this conversation as resolved.
Show resolved Hide resolved
super(BigQueryExecutionError, self).__init__('BigQuery job {} failed: {}'.format(job_id, error_message))
tomasaschan marked this conversation as resolved.
Show resolved Hide resolved
self.error_message = error_message
self.job_id = job_id