Class: Google::Cloud::Bigquery::Job
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Job
- Defined in:
- lib/google/cloud/bigquery/job.rb,
lib/google/cloud/bigquery/job/list.rb
Overview
Job
Represents a generic Job that may be performed on a Table.
The subclasses of Job represent the specific BigQuery job types: CopyJob, ExtractJob, LoadJob, and QueryJob.
A job instance is created when you call Project#query_job, Dataset#query_job, Table#copy, Table#extract, Table#load, or View#data.
Direct Known Subclasses
Defined Under Namespace
Classes: List
Instance Method Summary collapse
-
#configuration ⇒ Object
(also: #config)
The configuration for the job.
-
#created_at ⇒ Object
The time when the job was created.
-
#done? ⇒ Boolean
Checks if the job's state is
DONE
. -
#ended_at ⇒ Object
The time when the job ended.
-
#error ⇒ Hash
The last error for the job, if any errors have occurred.
-
#errors ⇒ Object
The errors for the job, if any errors have occurred.
-
#failed? ⇒ Boolean
Checks if an error is present.
-
#job_id ⇒ Object
The ID of the job.
-
#pending? ⇒ Boolean
Checks if the job's state is
PENDING
. -
#project_id ⇒ Object
The ID of the project containing the job.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the job with current data from the BigQuery service.
-
#rerun! ⇒ Object
Created a new job with the current configuration.
-
#running? ⇒ Boolean
Checks if the job's state is
RUNNING
. -
#started_at ⇒ Object
The time when the job was started.
-
#state ⇒ Object
The current state of the job.
-
#statistics ⇒ Object
(also: #stats)
The statistics for the job.
-
#status ⇒ Object
The job's status.
-
#wait_until_done! ⇒ Object
Refreshes the job until the job is
DONE
.
Instance Method Details
#configuration ⇒ Object Also known as: config
The configuration for the job. Returns a hash.
159 160 161 |
# File 'lib/google/cloud/bigquery/job.rb', line 159 def configuration JSON.parse @gapi.configuration.to_json end |
#created_at ⇒ Object
The time when the job was created.
129 130 131 132 133 |
# File 'lib/google/cloud/bigquery/job.rb', line 129 def created_at Time.at(Integer(@gapi.statistics.creation_time) / 1000.0) rescue nil end |
#done? ⇒ Boolean
Checks if the job's state is DONE
. When true
, the job has stopped
running. However, a DONE
state does not mean that the job completed
successfully. Use #failed? to detect if an error occurred or if the
job was successful.
116 117 118 119 |
# File 'lib/google/cloud/bigquery/job.rb', line 116 def done? return false if state.nil? "done".casecmp(state).zero? end |
#ended_at ⇒ Object
The time when the job ended.
This field is present when the job's state is DONE
.
148 149 150 151 152 |
# File 'lib/google/cloud/bigquery/job.rb', line 148 def ended_at Time.at(Integer(@gapi.statistics.end_time) / 1000.0) rescue nil end |
#error ⇒ Hash
The last error for the job, if any errors have occurred. Returns a hash.
195 196 197 198 199 |
# File 'lib/google/cloud/bigquery/job.rb', line 195 def error return nil if @gapi.status.nil? return nil if @gapi.status.error_result.nil? JSON.parse @gapi.status.error_result.to_json end |
#errors ⇒ Object
The errors for the job, if any errors have occurred. Returns an array of hash objects. See #error.
204 205 206 207 |
# File 'lib/google/cloud/bigquery/job.rb', line 204 def errors return [] if @gapi.status.nil? Array(@gapi.status.errors).map { |e| JSON.parse e.to_json } end |
#failed? ⇒ Boolean
Checks if an error is present.
123 124 125 |
# File 'lib/google/cloud/bigquery/job.rb', line 123 def failed? !error.nil? end |
#job_id ⇒ Object
The ID of the job.
77 78 79 |
# File 'lib/google/cloud/bigquery/job.rb', line 77 def job_id @gapi.job_reference.job_id end |
#pending? ⇒ Boolean
Checks if the job's state is PENDING
.
106 107 108 109 |
# File 'lib/google/cloud/bigquery/job.rb', line 106 def pending? return false if state.nil? "pending".casecmp(state).zero? end |
#project_id ⇒ Object
The ID of the project containing the job.
83 84 85 |
# File 'lib/google/cloud/bigquery/job.rb', line 83 def project_id @gapi.job_reference.project_id end |
#reload! ⇒ Object Also known as: refresh!
Reloads the job with current data from the BigQuery service.
219 220 221 222 223 |
# File 'lib/google/cloud/bigquery/job.rb', line 219 def reload! ensure_service! gapi = service.get_job job_id @gapi = gapi end |
#rerun! ⇒ Object
Created a new job with the current configuration.
211 212 213 214 215 |
# File 'lib/google/cloud/bigquery/job.rb', line 211 def rerun! ensure_service! gapi = service.insert_job @gapi.configuration Job.from_gapi gapi, service end |
#running? ⇒ Boolean
Checks if the job's state is RUNNING
.
99 100 101 102 |
# File 'lib/google/cloud/bigquery/job.rb', line 99 def running? return false if state.nil? "running".casecmp(state).zero? end |
#started_at ⇒ Object
The time when the job was started.
This field is present after the job's state changes from PENDING
to either RUNNING
or DONE
.
139 140 141 142 143 |
# File 'lib/google/cloud/bigquery/job.rb', line 139 def started_at Time.at(Integer(@gapi.statistics.start_time) / 1000.0) rescue nil end |
#state ⇒ Object
The current state of the job. The possible values are PENDING
,
RUNNING
, and DONE
. A DONE
state does not mean that the job
completed successfully. Use #failed? to discover if an error
occurred or if the job was successful.
92 93 94 95 |
# File 'lib/google/cloud/bigquery/job.rb', line 92 def state return nil if @gapi.status.nil? @gapi.status.state end |
#statistics ⇒ Object Also known as: stats
The statistics for the job. Returns a hash.
169 170 171 |
# File 'lib/google/cloud/bigquery/job.rb', line 169 def statistics JSON.parse @gapi.statistics.to_json end |
#status ⇒ Object
177 178 179 |
# File 'lib/google/cloud/bigquery/job.rb', line 177 def status JSON.parse @gapi.status.to_json end |
#wait_until_done! ⇒ Object
Refreshes the job until the job is DONE
.
The delay between refreshes will incrementally increase.
242 243 244 245 246 247 248 249 250 |
# File 'lib/google/cloud/bigquery/job.rb', line 242 def wait_until_done! backoff = ->(retries) { sleep 2 * retries + 5 } retries = 0 until done? backoff.call retries retries += 1 reload! end end |