td-client 0.8.44 → 0.8.45

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ == 2012-01-25 version 0.8.45
2
+
3
+ * Re-implement Client#job_status using /v3/job/status/job_id
4
+ instead of /v3/job/show/job_id to poll the progress of a job
5
+
6
+
1
7
  == 2012-01-23 version 0.8.44
2
8
 
3
9
  * Re-add json gem dependency
@@ -140,11 +140,9 @@ class Client
140
140
  Job.new(self, job_id, type, query, status, url, debug, start_at, end_at, nil, result_url, hive_result_schema, priority, retry_limit, org, db)
141
141
  end
142
142
 
143
- # => type:Symbol, url:String
143
+ # => status:String
144
144
  def job_status(job_id)
145
- # use v3/job/status instead of v3/job/show to poll finish of a job
146
- type, query, status, url, debug, start_at, end_at, result_url, hive_result_schema, priority, retry_limit, org, db = @api.show_job(job_id)
147
- return query, status, url, debug, start_at, end_at, result_url, hive_result_schema, priority, retry_limit, org, db
145
+ return @api.job_status(job_id)
148
146
  end
149
147
 
150
148
  # => result:[{column:String=>value:Object]
@@ -397,6 +397,16 @@ class API
397
397
  return [type, query, status, url, debug, start_at, end_at, result, hive_result_schema, priority, retry_limit, organization, database]
398
398
  end
399
399
 
400
+ def job_status(job_id)
401
+ code, body, res = get("/v3/job/status/#{e job_id}")
402
+ if code != "200"
403
+ raise_error("Get job status failed", res)
404
+ end
405
+
406
+ js = checked_json(body, %w[status])
407
+ return js['status']
408
+ end
409
+
400
410
  def job_result(job_id)
401
411
  require 'msgpack'
402
412
  code, body, res = get("/v3/job/result/#{e job_id}", {'format'=>'msgpack'})
@@ -309,8 +309,8 @@ class Job < Model
309
309
  end
310
310
 
311
311
  def finished?
312
- update_status! unless @status
313
- if FINISHED_STATUS.include?(@status)
312
+ update_progress! unless @status
313
+ if FINISHED_STATUS.include?(@status)
314
314
  return true
315
315
  else
316
316
  return false
@@ -322,22 +322,26 @@ class Job < Model
322
322
  end
323
323
 
324
324
  def success?
325
- update_status! unless @status
325
+ update_progress! unless @status
326
326
  @status == "success"
327
327
  end
328
328
 
329
329
  def error?
330
- update_status! unless @status
330
+ update_progress! unless @status
331
331
  @status == "error"
332
332
  end
333
333
 
334
334
  def killed?
335
- update_status! unless @status
335
+ update_progress! unless @status
336
336
  @status == "killed"
337
337
  end
338
338
 
339
+ def update_progress!
340
+ @status = @client.job_status(@job_id)
341
+ end
342
+
339
343
  def update_status!
340
- query, status, url, debug, start_at, end_at, result_url, hive_result_schema, priority, retry_limit, org_name, db_name = @client.job_status(@job_id)
344
+ type, query, status, url, debug, start_at, end_at, result_url, hive_result_schema, priority, retry_limit, org_name, db_name = @client.api.show_job(@job_id)
341
345
  @query = query
342
346
  @status = status
343
347
  @url = url
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.8.44'
3
+ VERSION = '0.8.45'
4
4
 
5
5
  end
@@ -74,6 +74,26 @@ describe 'Job API' do
74
74
  end
75
75
  end
76
76
 
77
+ describe 'job status' do
78
+ (0...MAX_JOB).each { |i|
79
+ it 'should return the status of a job #{i}' do
80
+ job_id = i.to_s
81
+ raw_job = raw_jobs[i]
82
+ result_job = {
83
+ 'job_id' => raw_job['job_id'],
84
+ 'status' => raw_job['status'],
85
+ 'created_at' => raw_job['created_at'],
86
+ 'start_at' => raw_job['start_at'],
87
+ 'end_at' => raw_job['end_at'],
88
+ }
89
+ stub_api_request(:get, "/v3/job/status/#{e(job_id)}").to_return(:body => result_job.to_json)
90
+
91
+ status = api.job_status(job_id)
92
+ status.should == (i.odd? ? 'success' : 'error')
93
+ end
94
+ }
95
+ end
96
+
77
97
  describe 'hive_query' do
78
98
  let :return_body do
79
99
  {:body => {'job_id' => '1'}.to_json}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.44
4
+ version: 0.8.45
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack