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
- 
  
    
      #cancel  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Cancels the job.
 - 
  
    
      #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
#cancel ⇒ Object
Cancels the job.
      210 211 212 213 214 215  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 210 def cancel ensure_service! resp = service.cancel_job job_id @gapi = resp.job true end  | 
  
#configuration ⇒ Object Also known as: config
The configuration for the job. Returns a hash.
      158 159 160  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 158 def configuration JSON.parse @gapi.configuration.to_json end  | 
  
#created_at ⇒ Object
The time when the job was created.
      128 129 130 131 132  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 128 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.
      115 116 117 118  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 115 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.
      147 148 149 150 151  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 147 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.
      194 195 196 197 198  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 194 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.
      203 204 205 206  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 203 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.
      122 123 124  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 122 def failed? !error.nil? end  | 
  
#job_id ⇒ Object
The ID of the job.
      76 77 78  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 76 def job_id @gapi.job_reference.job_id end  | 
  
#pending? ⇒ Boolean
Checks if the job's state is PENDING.
      105 106 107 108  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 105 def pending? return false if state.nil? "pending".casecmp(state).zero? end  | 
  
#project_id ⇒ Object
The ID of the project containing the job.
      82 83 84  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 82 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.
      227 228 229 230 231  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 227 def reload! ensure_service! gapi = service.get_job job_id @gapi = gapi end  | 
  
#rerun! ⇒ Object
Created a new job with the current configuration.
      219 220 221 222 223  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 219 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.
      98 99 100 101  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 98 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.
      138 139 140 141 142  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 138 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.
      91 92 93 94  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 91 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.
      168 169 170  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 168 def statistics JSON.parse @gapi.statistics.to_json end  | 
  
#status ⇒ Object
      176 177 178  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 176 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.
      249 250 251 252 253 254 255 256 257  | 
    
      # File 'lib/google/cloud/bigquery/job.rb', line 249 def wait_until_done! backoff = ->(retries) { sleep 2 * retries + 5 } retries = 0 until done? backoff.call retries retries += 1 reload! end end  |