Class: ScraperUtils::Scheduler::ThreadResponse
- Inherits:
-
Object
- Object
- ScraperUtils::Scheduler::ThreadResponse
- Defined in:
- lib/scraper_utils/scheduler/thread_response.rb
Overview
Encapsulates a response from an asynchronous command execution
Instance Attribute Summary collapse
-
#authority ⇒ Symbol
readonly
The authority from the original command.
-
#delay_till ⇒ Time?
Optionally delay the next process.
-
#error ⇒ Exception?
readonly
Any error that occurred during execution.
-
#result ⇒ Object?
readonly
The result of the command.
-
#time_taken ⇒ Float
readonly
The time taken to execute the command in seconds.
Instance Method Summary collapse
-
#initialize(authority, result, error, time_taken) ⇒ ThreadResponse
constructor
Initialize a new async response.
-
#inspect ⇒ String
Provide a readable inspection of the response.
-
#result! ⇒ Object
Return result or raise error.
-
#success? ⇒ Boolean
Check if the command execution was successful.
Constructor Details
#initialize(authority, result, error, time_taken) ⇒ ThreadResponse
Initialize a new async response
28 29 30 31 32 33 34 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 28 def initialize(, result, error, time_taken) @authority = @result = result @error = error @time_taken = time_taken @delay_till = nil end |
Instance Attribute Details
#authority ⇒ Symbol (readonly)
Returns The authority from the original command.
8 9 10 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 8 def @authority end |
#delay_till ⇒ Time?
Returns Optionally delay the next process.
20 21 22 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 20 def delay_till @delay_till end |
#error ⇒ Exception? (readonly)
Returns Any error that occurred during execution.
14 15 16 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 14 def error @error end |
#result ⇒ Object? (readonly)
Returns The result of the command.
11 12 13 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 11 def result @result end |
#time_taken ⇒ Float (readonly)
Returns 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
#inspect ⇒ String
Provide a readable inspection of the response
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=#{} #{status}#{error_info} time=#{time_taken}>" end |
#result! ⇒ Object
Return result or raise error
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
39 40 41 |
# File 'lib/scraper_utils/scheduler/thread_response.rb', line 39 def success? @error.nil? end |