kura 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afeddc460c9e0c9ad0b34eb12e0c162271774dc6
4
- data.tar.gz: 313412d9b2195bf4b57f6d3214eadb762c257c7a
3
+ metadata.gz: a43b8117003920b804b11dc4ea494d4055c78cff
4
+ data.tar.gz: ec0b100e696809181e1d15623ba8d7a70e02a11e
5
5
  SHA512:
6
- metadata.gz: 92432abce43b19932f34d3722828c58fd783c34f0a31271534765c256d86d2285ba522608c6327c402c842507555a87b7cffe7cc2756a5a3186755daa595cd16
7
- data.tar.gz: e7e09872aeedc94f1f57250cffc47d8af86fa53a7bcf6f6d731f100f65aa2ba0d3b8b7d622172d475d1c299100e44aeac5730f9ff7db736cad473a69d3d6b853
6
+ metadata.gz: 9b37896a3d33c84502fd998e8aab0e283dbd207f78fb6be72ffdca68c339e33d531b620effe26b727bbce260437a740ecb1a3511a7362749809148151e95f6f0
7
+ data.tar.gz: fc63b4a36b3280448a38c99e09de3a49f3ba8cf2938fcf60ea889ef08d4bcbdf1f99e15c8b66c41bcfd675da53f2686f392e2ed865a4cc2b9060449d9e3c88e6
@@ -1,3 +1,17 @@
1
+ # 0.2.2
2
+
3
+ ## Enhancements
4
+
5
+ * Add Kura::Client#cancel_job. Support jobs.cancel API.
6
+ https://cloud.google.com/bigquery/docs/reference/v2/jobs/cancel
7
+ * Kura::Client#wait_job accept Google::Apis::BigqueryV2::Job instance.
8
+ * Add Google::Apis::BigqueryV2::Job#wait and #cancel methods.
9
+
10
+ ## Incompatible Changes
11
+
12
+ * Kura::Client#insert_job (and #query, #load, #extract, #copy) return job
13
+ object (Google::Apis::BigqueryV2::Job instance) instead of job id (String).
14
+
1
15
  # 0.2.1
2
16
 
3
17
  ## Enhancements
@@ -3,6 +3,7 @@
3
3
  require "google/apis/bigquery_v2"
4
4
  require "googleauth"
5
5
  require "kura/version"
6
+ require "kura/extensions"
6
7
 
7
8
  module Kura
8
9
  class Client
@@ -176,15 +177,15 @@ module Kura
176
177
  end
177
178
  private :mode_to_write_disposition
178
179
 
179
- def insert_job(configuration, project_id: @default_project_id, media: nil, wait: nil)
180
+ def insert_job(configuration, project_id: @default_project_id, media: nil, wait: nil, &blk)
180
181
  job_object = Google::Apis::BigqueryV2::Job.new
181
182
  job_object.configuration = configuration
182
- result = @api.insert_job(project_id, job_object, upload_source: media)
183
- job_id = result.job_reference.job_id
183
+ job = @api.insert_job(project_id, job_object, upload_source: media)
184
+ job.kura_api = self
184
185
  if wait
185
- wait_job(job_id, wait, project_id: project_id)
186
+ wait_job(job, wait, &blk)
186
187
  else
187
- job_id
188
+ job
188
189
  end
189
190
  rescue
190
191
  process_error($!)
@@ -199,7 +200,8 @@ module Kura
199
200
  use_query_cache: true,
200
201
  project_id: @default_project_id,
201
202
  job_project_id: @default_project_id,
202
- wait: nil)
203
+ wait: nil,
204
+ &blk)
203
205
  write_disposition = mode_to_write_disposition(mode)
204
206
  configuration = {
205
207
  query: {
@@ -214,7 +216,7 @@ module Kura
214
216
  if dataset_id and table_id
215
217
  configuration[:query][:destination_table] = { project_id: project_id, dataset_id: dataset_id, table_id: table_id }
216
218
  end
217
- insert_job(configuration, wait: wait, project_id: job_project_id)
219
+ insert_job(configuration, wait: wait, project_id: job_project_id, &blk)
218
220
  end
219
221
 
220
222
  def normalize_schema(schema)
@@ -252,7 +254,8 @@ module Kura
252
254
  source_format: "CSV",
253
255
  project_id: @default_project_id,
254
256
  job_project_id: @default_project_id,
255
- file: nil, wait: nil)
257
+ file: nil, wait: nil,
258
+ &blk)
256
259
  write_disposition = mode_to_write_disposition(mode)
257
260
  source_uris = [source_uris] if source_uris.is_a?(String)
258
261
  configuration = {
@@ -281,7 +284,7 @@ module Kura
281
284
  unless file
282
285
  configuration[:load][:source_uris] = source_uris
283
286
  end
284
- insert_job(configuration, media: file, wait: wait, project_id: job_project_id)
287
+ insert_job(configuration, media: file, wait: wait, project_id: job_project_id, &blk)
285
288
  end
286
289
 
287
290
  def extract(dataset_id, table_id, dest_uris,
@@ -291,7 +294,8 @@ module Kura
291
294
  print_header: true,
292
295
  project_id: @default_project_id,
293
296
  job_project_id: @default_project_id,
294
- wait: nil)
297
+ wait: nil,
298
+ &blk)
295
299
  dest_uris = [ dest_uris ] if dest_uris.is_a?(String)
296
300
  configuration = {
297
301
  extract: {
@@ -309,7 +313,7 @@ module Kura
309
313
  configuration[:extract][:field_delimiter] = field_delimiter
310
314
  configuration[:extract][:print_header] = print_header
311
315
  end
312
- insert_job(configuration, wait: wait, project_id: job_project_id)
316
+ insert_job(configuration, wait: wait, project_id: job_project_id, &blk)
313
317
  end
314
318
 
315
319
  def copy(src_dataset_id, src_table_id, dest_dataset_id, dest_table_id,
@@ -317,7 +321,8 @@ module Kura
317
321
  src_project_id: @default_project_id,
318
322
  dest_project_id: @default_project_id,
319
323
  job_project_id: @default_project_id,
320
- wait: nil)
324
+ wait: nil,
325
+ &blk)
321
326
  write_disposition = mode_to_write_disposition(mode)
322
327
  configuration = {
323
328
  copy: {
@@ -334,15 +339,28 @@ module Kura
334
339
  write_disposition: write_disposition,
335
340
  }
336
341
  }
337
- insert_job(configuration, wait: wait, project_id: job_project_id)
342
+ insert_job(configuration, wait: wait, project_id: job_project_id, &blk)
338
343
  end
339
344
 
340
345
  def job(job_id, project_id: @default_project_id)
341
- @api.get_job(project_id, job_id)
346
+ @api.get_job(project_id, job_id).tap{|j| j.kura_api = self}
342
347
  rescue
343
348
  process_error($!)
344
349
  end
345
350
 
351
+ def cancel_job(job, project_id: @default_project_id)
352
+ case job
353
+ when String
354
+ jobid = job
355
+ when Google::Apis::BigqueryV2::Job
356
+ project_id = job.job_reference.project_id
357
+ jobid = job.job_reference.job_id
358
+ else
359
+ raise TypeError, "Kura::Client#cancel_job accept String(job-id) or Google::Apis::BigqueryV2::Job"
360
+ end
361
+ @api.cancel_job(project_id, jobid).job.tap{|j| j.kura_api = self}
362
+ end
363
+
346
364
  def job_finished?(r)
347
365
  if r.status.state == "DONE"
348
366
  if r.status.error_result
@@ -353,7 +371,16 @@ module Kura
353
371
  return false
354
372
  end
355
373
 
356
- def wait_job(job_id, timeout=60*10, project_id: @default_project_id)
374
+ def wait_job(job, timeout=60*10, project_id: @default_project_id)
375
+ case job
376
+ when String
377
+ job_id = job
378
+ when Google::Apis::BigqueryV2::Job
379
+ project_id = job.job_reference.project_id
380
+ job_id = job.job_reference.job_id
381
+ else
382
+ raise TypeError, "Kura::Client#wait_job accept String(job-id) or Google::Apis::BigqueryV2::Job"
383
+ end
357
384
  expire = Time.now + timeout
358
385
  while expire > Time.now
359
386
  j = job(job_id, project_id: project_id)
@@ -0,0 +1,3 @@
1
+ # coding: utf-8
2
+
3
+ require "kura/extensions/google/apis/bigquery_v2/job"
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require "google/apis/bigquery_v2"
4
+
5
+ class Google::Apis::BigqueryV2::Job
6
+ attr_accessor :kura_api
7
+
8
+ def wait(timeout, &blk)
9
+ kura_api.wait_job(self, timeout, &blk)
10
+ end
11
+
12
+ def cancel
13
+ kura_api.cancel_job(self)
14
+ end
15
+ end
16
+
@@ -1,3 +1,3 @@
1
1
  module Kura
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chikanaga Tomoyuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -126,6 +126,8 @@ files:
126
126
  - kura.gemspec
127
127
  - lib/kura.rb
128
128
  - lib/kura/client.rb
129
+ - lib/kura/extensions.rb
130
+ - lib/kura/extensions/google/apis/bigquery_v2/job.rb
129
131
  - lib/kura/version.rb
130
132
  homepage: https://github.com/nagachika/kura/
131
133
  licenses: