Class: TreasureData::Job

Inherits:
Model
  • Object
show all
Defined in:
lib/td/client/model.rb

Direct Known Subclasses

ScheduledJob

Constant Summary collapse

STATUS_QUEUED =
"queued"
STATUS_BOOTING =
"booting"
STATUS_RUNNING =
"running"
STATUS_SUCCESS =
"success"
STATUS_ERROR =
"error"
STATUS_KILLED =
"killed"
FINISHED_STATUS =
[STATUS_SUCCESS, STATUS_ERROR, STATUS_KILLED]

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Constructor Details

#initialize(client, job_id, type, query, status = nil, url = nil, debug = nil, start_at = nil, end_at = nil, cpu_time = nil, result_size = nil, result = nil, result_url = nil, hive_result_schema = nil, priority = nil, retry_limit = nil, org_name = nil, db_name = nil) ⇒ Job

Returns a new instance of Job.



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/td/client/model.rb', line 263

def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, cpu_time=nil,
               result_size=nil, result=nil, result_url=nil, hive_result_schema=nil, priority=nil, retry_limit=nil,
               org_name=nil, db_name=nil)
  super(client)
  @job_id = job_id
  @type = type
  @url = url
  @query = query
  @status = status
  @debug = debug
  @start_at = start_at
  @end_at = end_at
  @cpu_time = cpu_time
  @result_size = result_size
  @result = result
  @result_url = result_url
  @hive_result_schema = hive_result_schema
  @priority = priority
  @retry_limit = retry_limit
  @db_name = db_name
end

Instance Attribute Details

#db_nameObject (readonly)

Returns the value of attribute db_name.



286
287
288
# File 'lib/td/client/model.rb', line 286

def db_name
  @db_name
end

#job_idObject (readonly)

Returns the value of attribute job_id.



285
286
287
# File 'lib/td/client/model.rb', line 285

def job_id
  @job_id
end

#org_nameObject (readonly)

Returns the value of attribute org_name.



286
287
288
# File 'lib/td/client/model.rb', line 286

def org_name
  @org_name
end

#priorityObject (readonly)

Returns the value of attribute priority.



286
287
288
# File 'lib/td/client/model.rb', line 286

def priority
  @priority
end

#result_urlObject (readonly)

Returns the value of attribute result_url.



285
286
287
# File 'lib/td/client/model.rb', line 285

def result_url
  @result_url
end

#retry_limitObject (readonly)

Returns the value of attribute retry_limit.



286
287
288
# File 'lib/td/client/model.rb', line 286

def retry_limit
  @retry_limit
end

#typeObject (readonly)

Returns the value of attribute type.



285
286
287
# File 'lib/td/client/model.rb', line 285

def type
  @type
end

Instance Method Details

#cpu_timeObject



326
327
328
329
# File 'lib/td/client/model.rb', line 326

def cpu_time
  update_status! unless @cpu_time || finished?
  @cpu_time
end

#debugObject



311
312
313
314
# File 'lib/td/client/model.rb', line 311

def debug
  update_status! unless @debug || finished?
  @debug
end

#end_atObject



321
322
323
324
# File 'lib/td/client/model.rb', line 321

def end_at
  update_status! unless @end_at || finished?
  @end_at && !@end_at.empty? ? Time.parse(@end_at) : nil
end

#error?Boolean

Returns:

  • (Boolean)


382
383
384
385
# File 'lib/td/client/model.rb', line 382

def error?
  update_progress! unless @status
  @status == STATUS_ERROR
end

#finished?Boolean

Returns:

  • (Boolean)


372
373
374
375
# File 'lib/td/client/model.rb', line 372

def finished?
  update_progress! unless @status
  FINISHED_STATUS.include?(@status)
end

#hive_result_schemaObject



331
332
333
334
# File 'lib/td/client/model.rb', line 331

def hive_result_schema
  update_status! unless @hive_result_schema.instance_of? Array || finished?
  @hive_result_schema
end

#kill!Object



292
293
294
# File 'lib/td/client/model.rb', line 292

def kill!
  # TODO
end

#killed?Boolean

Returns:

  • (Boolean)


387
388
389
390
# File 'lib/td/client/model.rb', line 387

def killed?
  update_progress! unless @status
  @status == STATUS_KILLED
end

#queryObject



296
297
298
299
# File 'lib/td/client/model.rb', line 296

def query
  update_status! unless @query || finished?
  @query
end

#queued?Boolean

Returns:

  • (Boolean)


392
393
394
395
# File 'lib/td/client/model.rb', line 392

def queued?
  update_progress! unless @status
  @status == STATUS_QUEUED
end

#resultObject



341
342
343
344
345
346
347
# File 'lib/td/client/model.rb', line 341

def result
  unless @result
    return nil unless finished?
    @result = @client.job_result(@job_id)
  end
  @result
end

#result_each(&block) ⇒ Object



363
364
365
366
367
368
369
370
# File 'lib/td/client/model.rb', line 363

def result_each(&block)
  if @result
    @result.each(&block)
  else
    @client.job_result_each(@job_id, &block)
  end
  nil
end

#result_each_with_compr_size(&block) ⇒ Object



354
355
356
357
358
359
360
361
# File 'lib/td/client/model.rb', line 354

def result_each_with_compr_size(&block)
  if @result
    @result.each(&block)
  else
    @client.job_result_each_with_compr_size(@job_id, &block)
  end
  nil
end

#result_format(format, io = nil, &block) ⇒ Object



349
350
351
352
# File 'lib/td/client/model.rb', line 349

def result_format(format, io=nil, &block)
  return nil unless finished?
  @client.job_result_format(@job_id, format, io, &block)
end

#result_sizeObject



336
337
338
339
# File 'lib/td/client/model.rb', line 336

def result_size
  update_status! unless @result_size || finished?
  @result_size
end

#running?Boolean

Returns:

  • (Boolean)


397
398
399
400
# File 'lib/td/client/model.rb', line 397

def running?
  update_progress! unless @status
  @status == STATUS_RUNNING
end

#start_atObject



316
317
318
319
# File 'lib/td/client/model.rb', line 316

def start_at
  update_status! unless @start_at || finished?
  @start_at && !@start_at.empty? ? Time.parse(@start_at) : nil
end

#statusObject



301
302
303
304
# File 'lib/td/client/model.rb', line 301

def status
  update_status! unless @status || finished?
  @status
end

#success?Boolean

Returns:

  • (Boolean)


377
378
379
380
# File 'lib/td/client/model.rb', line 377

def success?
  update_progress! unless @status
  @status == STATUS_SUCCESS
end

#update_progress!Object



402
403
404
# File 'lib/td/client/model.rb', line 402

def update_progress!
  @status = @client.job_status(@job_id)
end

#update_status!Object



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/td/client/model.rb', line 406

def update_status!
  type, query, status, url, debug, start_at, end_at, cpu_time,
    result_size, result_url, hive_result_schema, priority, retry_limit,
    org_name, db_name = @client.api.show_job(@job_id)
  @query = query
  @status = status
  @url = url
  @debug = debug
  @start_at = start_at
  @end_at = end_at
  @cpu_time = cpu_time
  @result_size = result_size
  @result_url = result_url
  @hive_result_schema = hive_result_schema
  @priority = priority
  @retry_limit = retry_limit
  @db_name = db_name
  self
end

#urlObject



306
307
308
309
# File 'lib/td/client/model.rb', line 306

def url
  update_status! unless @url || finished?
  @url
end

#wait(timeout = nil) ⇒ Object



288
289
290
# File 'lib/td/client/model.rb', line 288

def wait(timeout=nil)
  # TODO
end