Class: ScraperUtils::Scheduler::ThreadResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/scraper_utils/scheduler/thread_response.rb

Overview

Encapsulates a response from an asynchronous command execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authority, result, error, time_taken) ⇒ ThreadResponse

Initialize a new async response

Parameters:

  • authority (Symbol)

    The authority from the original command

  • result (Object, nil)

    The result of the command

  • error (Exception, nil)

    Any error that occurred during execution

  • time_taken (Float)

    The time taken to submit_request the command in seconds



28
29
30
31
32
33
34
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 28

def initialize(authority, result, error, time_taken)
  @authority = authority
  @result = result
  @error = error
  @time_taken = time_taken
  @delay_till = nil
end

Instance Attribute Details

#authoritySymbol (readonly)

Returns The authority from the original command.

Returns:

  • (Symbol)

    The authority from the original command



8
9
10
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 8

def authority
  @authority
end

#delay_tillTime?

Returns Optionally delay the next process.

Returns:

  • (Time, nil)

    Optionally delay the next process



20
21
22
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 20

def delay_till
  @delay_till
end

#errorException? (readonly)

Returns Any error that occurred during execution.

Returns:

  • (Exception, nil)

    Any error that occurred during execution



14
15
16
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 14

def error
  @error
end

#resultObject? (readonly)

Returns The result of the command.

Returns:

  • (Object, nil)

    The result of the command



11
12
13
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 11

def result
  @result
end

#time_takenFloat (readonly)

Returns The time taken to execute the command in seconds.

Returns:

  • (Float)

    The time taken to execute the command in seconds



17
18
19
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 17

def time_taken
  @time_taken
end

Instance Method Details

#inspectString

Provide a readable inspection of the response

Returns:

  • (String)

    Readable representation



52
53
54
55
56
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 52

def inspect
  status = success? ? "success" : "FAILED"
  error_info = success? ? "" : " - #{error.class}: #{error}"
  "#<#{self.class} authority=#{authority} #{status}#{error_info} time=#{time_taken}>"
end

#result!Object

Return result or raise error

Returns:

  • (Object)

    Result pf request

Raises:



45
46
47
48
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 45

def result!
  return @result if success?
  raise @error
end

#success?Boolean

Check if the command execution was successful

Returns:

  • (Boolean)

    true if successful, false otherwise



39
40
41
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 39

def success?
  @error.nil?
end