class TreasureData::Job
Constants
- FINISHED_STATUS
- STATUS_BOOTING
- STATUS_ERROR
- STATUS_KILLED
- STATUS_QUEUED
- STATUS_RUNNING
- STATUS_SUCCESS
Attributes
@!attribute [r] job_id
@!attribute [r] type @!attribute [r] result_url
@!attribute [r] priority @!attribute [r] retry_limit
@!attribute [r] org_name
@!attribute [r] db_name
@!attribute [r] duration @!attribute [r] num_records
@!attribute [r] job_id
@!attribute [r] type @!attribute [r] result_url
@!attribute [r] priority @!attribute [r] retry_limit
@!attribute [r] org_name
@!attribute [r] db_name
@!attribute [r] duration @!attribute [r] num_records
@!attribute [r] job_id
@!attribute [r] type @!attribute [r] result_url
@!attribute [r] priority @!attribute [r] retry_limit
@!attribute [r] org_name
@!attribute [r] db_name
@!attribute [r] duration @!attribute [r] num_records
Public Class Methods
@param [TreasureData::Client] client @param [String] job_id
@param [String] type @param [String] query @param [Fixnum] status @param [String] url @param [Boolean] debug @param [String] start_at
@param [String] end_at
@param [String] cpu_time
@param [String] result_size
@param [Array] result @param [String] result_url
@param [Array] hive_result_schema
@param [Fixnum] priority @param [Fixnum] retry_limit
@param [String] org_name
@param [String] db_name
@param [Fixnum] duration @param [Fixnum] num_records
TreasureData::Model::new
# File lib/td/client/model.rb, line 407 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 @auto_update_status = true end
Public Instance Methods
set whether it update status if the job is not finished yet or not
# File lib/td/client/model.rb, line 451 def auto_update_status=(bool) @auto_update_status = bool ? true : false end
whether it update status if the job is not finished yet or not
# File lib/td/client/model.rb, line 446 def auto_update_status? @auto_update_status end
@return [String]
# File lib/td/client/model.rb, line 528 def cpu_time update_status! unless @cpu_time || !@auto_update_status || finished? @cpu_time end
@return [Boolean]
# File lib/td/client/model.rb, line 510 def debug update_status! unless @debug || !@auto_update_status || finished? @debug end
@return [Time, nil]
# File lib/td/client/model.rb, line 522 def end_at update_status! unless @end_at || !@auto_update_status || finished? @end_at && !@end_at.empty? ? Time.parse(@end_at) : nil end
@return [Boolean]
# File lib/td/client/model.rb, line 603 def error? update_progress! unless @status @status == STATUS_ERROR end
@return [Boolean]
# File lib/td/client/model.rb, line 591 def finished? update_progress! unless @status FINISHED_STATUS.include?(@status) end
@return [Array]
# File lib/td/client/model.rb, line 534 def hive_result_schema update_status! unless @hive_result_schema.instance_of?(Array) || !@auto_update_status || finished? @hive_result_schema end
# File lib/td/client/model.rb, line 487 def kill! # TODO end
@return [Boolean]
# File lib/td/client/model.rb, line 609 def killed? update_progress! unless @status @status == STATUS_KILLED end
@return [String]
# File lib/td/client/model.rb, line 492 def query update_status! unless @query || !@auto_update_status || finished? @query end
@return [Boolean]
# File lib/td/client/model.rb, line 615 def queued? update_progress! unless @status @status == STATUS_QUEUED end
@return [Array]
# File lib/td/client/model.rb, line 546 def result unless @result return nil unless finished? @result = @client.job_result(@job_id) end @result end
@yield [result] @return [nil]
# File lib/td/client/model.rb, line 581 def result_each(&block) if @result @result.each(&block) else @client.job_result_each(@job_id, &block) end nil end
@yield [result] @return [nil]
# File lib/td/client/model.rb, line 570 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
@param [String] format @param [IO] io @param [Proc] block @return [nil, String]
# File lib/td/client/model.rb, line 558 def result_format(format, io=nil, &block) return nil unless finished? @client.job_result_format(@job_id, format, io, &block) end
# File lib/td/client/model.rb, line 563 def result_raw(format, io=nil, &block) return nil unless finished? @client.job_result_raw(@job_id, format, io, &block) end
@return [String]
# File lib/td/client/model.rb, line 540 def result_size update_status! unless @result_size || !@auto_update_status || finished? @result_size end
@return [Boolean]
# File lib/td/client/model.rb, line 621 def running? update_progress! unless @status @status == STATUS_RUNNING end
@return [Time, nil]
# File lib/td/client/model.rb, line 516 def start_at update_status! unless @start_at || !@auto_update_status || finished? @start_at && !@start_at.empty? ? Time.parse(@start_at) : nil end
@return [String]
# File lib/td/client/model.rb, line 498 def status update_status! unless @status || !@auto_update_status || finished? @status end
@return [Boolean]
# File lib/td/client/model.rb, line 597 def success? update_progress! unless @status @status == STATUS_SUCCESS end
# File lib/td/client/model.rb, line 626 def update_progress! @status = @client.job_status(@job_id) end
# File lib/td/client/model.rb, line 630 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
@return [String]
# File lib/td/client/model.rb, line 504 def url update_status! unless @url || !@auto_update_status || finished? @url end
@option timeout [Integer,nil] timeout in second @option wait_interval [Integer,nil] interval in second of polling the job status @param detail [Boolean] update job detail or not @param verbose [Boolean] out retry log to stderr or not
# File lib/td/client/model.rb, line 459 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, $!.message 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
Private Instance Methods
# File lib/td/client/model.rb, line 653 def monotonic_clock if defined?(Process.clock_gettime) Process.clock_gettime(Process::CLOCK_MONOTONIC) else Time.now.to_i end end