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, duration = nil) ⇒ Job

Returns a new instance of Job.

Parameters:

  • client (TreasureData::Client)
  • job_id (String)
  • type (String)
  • query (String)
  • status (Fixnum) (defaults to: nil)
  • url (String) (defaults to: nil)
  • debug (Boolean) (defaults to: nil)
  • start_at (String) (defaults to: nil)
  • end_at (String) (defaults to: nil)
  • cpu_time (String) (defaults to: nil)
  • result_size (String) (defaults to: nil)
  • result (Array) (defaults to: nil)
  • result_url (String) (defaults to: nil)
  • hive_result_schema (Array) (defaults to: nil)
  • priority (Fixnum) (defaults to: nil)
  • retry_limit (Fixnum) (defaults to: nil)
  • org_name (String) (defaults to: nil)
  • db_name (String) (defaults to: nil)
  • duration (Fixnum) (defaults to: nil)


371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/td/client/model.rb', line 371

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, duration=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
  @duration = duration
end

Instance Attribute Details

#db_nameObject (readonly)

Returns the value of attribute db_name.



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

attr_reader :job_id, :type, :result_url

#durationObject (readonly)

Returns the value of attribute duration.



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

attr_reader :job_id, :type, :result_url

#job_idObject (readonly)



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

def job_id
  @job_id
end

#org_nameObject (readonly)

Returns the value of attribute org_name.



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

attr_reader :job_id, :type, :result_url

#priorityObject (readonly)

Returns the value of attribute priority.



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

attr_reader :job_id, :type, :result_url

#result_urlObject (readonly)

Returns the value of attribute result_url.



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

attr_reader :job_id, :type, :result_url

#retry_limitObject (readonly)

Returns the value of attribute retry_limit.



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

attr_reader :job_id, :type, :result_url

#typeObject (readonly)



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

attr_reader :job_id, :type, :result_url

Instance Method Details

#cpu_timeString

Returns:

  • (String)


451
452
453
454
# File 'lib/td/client/model.rb', line 451

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

#debugBoolean

Returns:

  • (Boolean)


433
434
435
436
# File 'lib/td/client/model.rb', line 433

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

#end_atTime?

Returns:

  • (Time, nil)


445
446
447
448
# File 'lib/td/client/model.rb', line 445

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

#error?Boolean

Returns:

  • (Boolean)


526
527
528
529
# File 'lib/td/client/model.rb', line 526

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

#finished?Boolean

Returns:

  • (Boolean)


514
515
516
517
# File 'lib/td/client/model.rb', line 514

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

#hive_result_schemaArray

Returns:

  • (Array)


457
458
459
460
# File 'lib/td/client/model.rb', line 457

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

#kill!Object



410
411
412
# File 'lib/td/client/model.rb', line 410

def kill!
  # TODO
end

#killed?Boolean

Returns:

  • (Boolean)


532
533
534
535
# File 'lib/td/client/model.rb', line 532

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

#queryString

Returns:

  • (String)


415
416
417
418
# File 'lib/td/client/model.rb', line 415

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

#queued?Boolean

Returns:

  • (Boolean)


538
539
540
541
# File 'lib/td/client/model.rb', line 538

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

#resultArray

Returns:

  • (Array)


469
470
471
472
473
474
475
# File 'lib/td/client/model.rb', line 469

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

#result_each {|result| ... } ⇒ nil

Yields:

Returns:

  • (nil)


504
505
506
507
508
509
510
511
# File 'lib/td/client/model.rb', line 504

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 {|result| ... } ⇒ nil

Yields:

Returns:

  • (nil)


493
494
495
496
497
498
499
500
# File 'lib/td/client/model.rb', line 493

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) ⇒ nil, String

Parameters:

  • format (String)
  • io (IO) (defaults to: nil)
  • block (Proc)

Returns:

  • (nil, String)


481
482
483
484
# File 'lib/td/client/model.rb', line 481

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

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



486
487
488
489
# File 'lib/td/client/model.rb', line 486

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

#result_sizeString

Returns:

  • (String)


463
464
465
466
# File 'lib/td/client/model.rb', line 463

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

#running?Boolean

Returns:

  • (Boolean)


544
545
546
547
# File 'lib/td/client/model.rb', line 544

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

#start_atTime?

Returns:

  • (Time, nil)


439
440
441
442
# File 'lib/td/client/model.rb', line 439

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

#statusString

Returns:

  • (String)


421
422
423
424
# File 'lib/td/client/model.rb', line 421

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

#success?Boolean

Returns:

  • (Boolean)


520
521
522
523
# File 'lib/td/client/model.rb', line 520

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

#update_progress!Object



549
550
551
# File 'lib/td/client/model.rb', line 549

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

#update_status!Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/td/client/model.rb', line 553

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

#urlString

Returns:

  • (String)


427
428
429
430
# File 'lib/td/client/model.rb', line 427

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

#wait(timeout = nil) ⇒ Object



406
407
408
# File 'lib/td/client/model.rb', line 406

def wait(timeout=nil)
  # TODO
end