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, 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.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/td/client/model.rb', line 234

def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=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
  @result = result
  @result_url = result_url
  @hive_result_schema = hive_result_schema
  @priority = priority
  @retry_limit = retry_limit
  @org_name = org_name
  @db_name = db_name
end

Instance Attribute Details

#db_nameObject (readonly)

Returns the value of attribute db_name.



254
255
256
# File 'lib/td/client/model.rb', line 254

def db_name
  @db_name
end

#hive_result_schemaObject (readonly)

Returns the value of attribute hive_result_schema.



254
255
256
# File 'lib/td/client/model.rb', line 254

def hive_result_schema
  @hive_result_schema
end

#job_idObject (readonly)

Returns the value of attribute job_id.



253
254
255
# File 'lib/td/client/model.rb', line 253

def job_id
  @job_id
end

#org_nameObject (readonly)

Returns the value of attribute org_name.



254
255
256
# File 'lib/td/client/model.rb', line 254

def org_name
  @org_name
end

#priorityObject (readonly)

Returns the value of attribute priority.



254
255
256
# File 'lib/td/client/model.rb', line 254

def priority
  @priority
end

#result_urlObject (readonly)

Returns the value of attribute result_url.



253
254
255
# File 'lib/td/client/model.rb', line 253

def result_url
  @result_url
end

#retry_limitObject (readonly)

Returns the value of attribute retry_limit.



254
255
256
# File 'lib/td/client/model.rb', line 254

def retry_limit
  @retry_limit
end

#typeObject (readonly)

Returns the value of attribute type.



253
254
255
# File 'lib/td/client/model.rb', line 253

def type
  @type
end

Instance Method Details

#debugObject



279
280
281
282
# File 'lib/td/client/model.rb', line 279

def debug
  update_status! unless @debug
  @debug
end

#end_atObject



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

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

#error?Boolean

Returns:

  • (Boolean)


334
335
336
337
# File 'lib/td/client/model.rb', line 334

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

#finished?Boolean

Returns:

  • (Boolean)


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

def finished?
  update_progress! unless @status
  if FINISHED_STATUS.include?(@status)      
    return true
  else
    return false
  end
end

#kill!Object



260
261
262
# File 'lib/td/client/model.rb', line 260

def kill!
  # TODO
end

#killed?Boolean

Returns:

  • (Boolean)


339
340
341
342
# File 'lib/td/client/model.rb', line 339

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

#queryObject



264
265
266
267
# File 'lib/td/client/model.rb', line 264

def query
  update_status! unless @query
  @query
end

#resultObject



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

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

#result_each(&block) ⇒ Object



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

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

#result_format(format, io = nil) ⇒ Object



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

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

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  !finished?
end

#start_atObject



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

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

#statusObject



269
270
271
272
# File 'lib/td/client/model.rb', line 269

def status
  update_status! unless @status
  @status
end

#success?Boolean

Returns:

  • (Boolean)


329
330
331
332
# File 'lib/td/client/model.rb', line 329

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

#update_progress!Object



344
345
346
# File 'lib/td/client/model.rb', line 344

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

#update_status!Object



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/td/client/model.rb', line 348

def update_status!
  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)
  @query = query
  @status = status
  @url = url
  @debug = debug
  @start_at = start_at
  @end_at = end_at
  @hive_result_schema = hive_result_schema
  @priority = priority
  @retry_limit = retry_limit
  @org_name = org_name
  @db_name = db_name
  self
end

#urlObject



274
275
276
277
# File 'lib/td/client/model.rb', line 274

def url
  update_status! unless @url
  @url
end

#wait(timeout = nil) ⇒ Object



256
257
258
# File 'lib/td/client/model.rb', line 256

def wait(timeout=nil)
  # TODO
end