Class: TreasureData::Job
Direct Known Subclasses
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
- 
  
    
      #db_name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute db_name. 
- 
  
    
      #duration  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute duration. 
- #job_id ⇒ Object readonly
- 
  
    
      #num_records  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute num_records. 
- 
  
    
      #org_name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute org_name. 
- 
  
    
      #priority  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute priority. 
- 
  
    
      #result_url  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute result_url. 
- 
  
    
      #retry_limit  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute retry_limit. 
- #type ⇒ Object readonly
Attributes inherited from Model
Instance Method Summary collapse
- #cpu_time ⇒ String
- #debug ⇒ Boolean
- #end_at ⇒ Time?
- #error? ⇒ Boolean
- #finished? ⇒ Boolean
- #hive_result_schema ⇒ Array
- 
  
    
      #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, num_records = nil)  ⇒ Job 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Job. 
- #kill! ⇒ Object
- #killed? ⇒ Boolean
- #query ⇒ String
- #queued? ⇒ Boolean
- #result ⇒ Array
- #result_each {|result| ... } ⇒ nil
- #result_each_with_compr_size {|result| ... } ⇒ nil
- #result_format(format, io = nil, &block) ⇒ nil, String
- #result_raw(format, io = nil, &block) ⇒ Object
- #result_size ⇒ String
- #running? ⇒ Boolean
- #start_at ⇒ Time?
- #status ⇒ String
- #success? ⇒ Boolean
- #update_progress! ⇒ Object
- #update_status! ⇒ Object
- #url ⇒ String
- #wait(*args) ⇒ Object
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, num_records = nil) ⇒ Job
Returns a new instance of Job.
| 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | # File 'lib/td/client/model.rb', line 406 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, num_records=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 @num_records = num_records end | 
Instance Attribute Details
#db_name ⇒ Object (readonly)
Returns the value of attribute db_name.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#job_id ⇒ Object (readonly)
| 439 440 441 | # File 'lib/td/client/model.rb', line 439 def job_id @job_id end | 
#num_records ⇒ Object (readonly)
Returns the value of attribute num_records.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#org_name ⇒ Object (readonly)
Returns the value of attribute org_name.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#result_url ⇒ Object (readonly)
Returns the value of attribute result_url.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#retry_limit ⇒ Object (readonly)
Returns the value of attribute retry_limit.
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
#type ⇒ Object (readonly)
| 439 | # File 'lib/td/client/model.rb', line 439 attr_reader :job_id, :type, :result_url | 
Instance Method Details
#cpu_time ⇒ String
| 516 517 518 519 | # File 'lib/td/client/model.rb', line 516 def cpu_time update_status! unless @cpu_time || finished? @cpu_time end | 
#debug ⇒ Boolean
| 498 499 500 501 | # File 'lib/td/client/model.rb', line 498 def debug update_status! unless @debug || finished? @debug end | 
#end_at ⇒ Time?
| 510 511 512 513 | # File 'lib/td/client/model.rb', line 510 def end_at update_status! unless @end_at || finished? @end_at && !@end_at.empty? ? Time.parse(@end_at) : nil end | 
#error? ⇒ Boolean
| 591 592 593 594 | # File 'lib/td/client/model.rb', line 591 def error? update_progress! unless @status @status == STATUS_ERROR end | 
#finished? ⇒ Boolean
| 579 580 581 582 | # File 'lib/td/client/model.rb', line 579 def finished? update_progress! unless @status FINISHED_STATUS.include?(@status) end | 
#hive_result_schema ⇒ Array
| 522 523 524 525 | # File 'lib/td/client/model.rb', line 522 def hive_result_schema update_status! unless @hive_result_schema.instance_of? Array || finished? @hive_result_schema end | 
#kill! ⇒ Object
| 475 476 477 | # File 'lib/td/client/model.rb', line 475 def kill! # TODO end | 
#killed? ⇒ Boolean
| 597 598 599 600 | # File 'lib/td/client/model.rb', line 597 def killed? update_progress! unless @status @status == STATUS_KILLED end | 
#query ⇒ String
| 480 481 482 483 | # File 'lib/td/client/model.rb', line 480 def query update_status! unless @query || finished? @query end | 
#queued? ⇒ Boolean
| 603 604 605 606 | # File 'lib/td/client/model.rb', line 603 def queued? update_progress! unless @status @status == STATUS_QUEUED end | 
#result ⇒ Array
| 534 535 536 537 538 539 540 | # File 'lib/td/client/model.rb', line 534 def result unless @result return nil unless finished? @result = @client.job_result(@job_id) end @result end | 
#result_each {|result| ... } ⇒ nil
| 569 570 571 572 573 574 575 576 | # File 'lib/td/client/model.rb', line 569 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
| 558 559 560 561 562 563 564 565 | # File 'lib/td/client/model.rb', line 558 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
| 546 547 548 549 | # File 'lib/td/client/model.rb', line 546 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
| 551 552 553 554 | # File 'lib/td/client/model.rb', line 551 def result_raw(format, io=nil, &block) return nil unless finished? @client.job_result_raw(@job_id, format, io, &block) end | 
#result_size ⇒ String
| 528 529 530 531 | # File 'lib/td/client/model.rb', line 528 def result_size update_status! unless @result_size || finished? @result_size end | 
#running? ⇒ Boolean
| 609 610 611 612 | # File 'lib/td/client/model.rb', line 609 def running? update_progress! unless @status @status == STATUS_RUNNING end | 
#start_at ⇒ Time?
| 504 505 506 507 | # File 'lib/td/client/model.rb', line 504 def start_at update_status! unless @start_at || finished? @start_at && !@start_at.empty? ? Time.parse(@start_at) : nil end | 
#status ⇒ String
| 486 487 488 489 | # File 'lib/td/client/model.rb', line 486 def status update_status! unless @status || finished? @status end | 
#success? ⇒ Boolean
| 585 586 587 588 | # File 'lib/td/client/model.rb', line 585 def success? update_progress! unless @status @status == STATUS_SUCCESS end | 
#update_progress! ⇒ Object
| 614 615 616 | # File 'lib/td/client/model.rb', line 614 def update_progress! @status = @client.job_status(@job_id) end | 
#update_status! ⇒ Object
| 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | # File 'lib/td/client/model.rb', line 618 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 , duration, num_records = @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 @duration = duration @num_records = num_records self end | 
#url ⇒ String
| 492 493 494 495 | # File 'lib/td/client/model.rb', line 492 def url update_status! unless @url || finished? @url end | 
#wait(*args) ⇒ Object
| 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | # File 'lib/td/client/model.rb', line 447 def wait(*args) opthash = Hash.try_convert(args.last) if opthash args.pop detail = opthash.fetch(:detail, false) verbose = opthash.fetch(:verbose, ENV['TD_CLIENT_DEBUG']) end timeout = args[0] wait_interval = args[1] || 2 deadline = monotonic_clock + timeout if timeout timeout_klass = Class.new(Exception) begin if timeout if deadline <= monotonic_clock raise timeout_klass, "timeout (#{timeout}) exceeded wait_interval=#{wait_interval}" end end sleep wait_interval detail ? update_status! : update_progress! yield self if block_given? rescue timeout_klass raise Timeout::Error, $!. rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError, SystemCallError, OpenSSL::SSL::SSLError, SocketError, HTTPClient::TimeoutError $stderr.puts "ignore network error (#{$!}); retry..." if verbose end until finished? end |