Class: ScraperUtils::Scheduler::ProcessRequest

Inherits:
ThreadRequest show all
Defined in:
lib/scraper_utils/scheduler/process_request.rb

Overview

Encapsulates a request to be executed (usually )asynchronously by the ThreadPool)

Instance Attribute Summary collapse

Attributes inherited from ThreadRequest

#authority

Instance Method Summary collapse

Methods inherited from ThreadRequest

#execute_block

Constructor Details

#initialize(authority, subject, method_name, args) ⇒ ProcessRequest

Initialize a new async request

Parameters:

  • authority (Symbol, nil)

    Authority for correlating requests and responses nil is used when threads are disabled to process locally without duplicating codd

  • subject (Object)

    The object to call the method on

  • method_name (Symbol)

    The method to call on the subject

  • args (Array)

    The arguments to pass to the method

Raises:

  • (ArgumentError)

    If any required parameter is missing or invalid



26
27
28
29
30
31
32
33
# File 'lib/scraper_utils/scheduler/process_request.rb', line 26

def initialize(authority, subject, method_name, args)
  super(authority)
  @subject = subject
  @method_name = method_name
  @args = args

  validate!
end

Instance Attribute Details

#argsArray (readonly)

Returns The arguments to pass to the method.

Returns:

  • (Array)

    The arguments to pass to the method



16
17
18
# File 'lib/scraper_utils/scheduler/process_request.rb', line 16

def args
  @args
end

#method_nameSymbol (readonly)

Returns The method to call on the subject.

Returns:

  • (Symbol)

    The method to call on the subject



13
14
15
# File 'lib/scraper_utils/scheduler/process_request.rb', line 13

def method_name
  @method_name
end

#subjectObject (readonly)

Returns The object to call the method on.

Returns:

  • (Object)

    The object to call the method on



10
11
12
# File 'lib/scraper_utils/scheduler/process_request.rb', line 10

def subject
  @subject
end

Instance Method Details

#executeThreadResponse

Execute the request by calling the method on the subject If the subject has an instance variable @delay_till then that is added to the response

Returns:



38
39
40
41
42
43
44
# File 'lib/scraper_utils/scheduler/process_request.rb', line 38

def execute
  result = execute_block do
    subject.send(method_name, *args)
  end
  result.delay_till = subject.instance_variable_get(:@delay_till)
  result
end