Class: Fragmentary::RequestQueue::Sender
- Inherits:
-
Object
- Object
- Fragmentary::RequestQueue::Sender
- Defined in:
- lib/fragmentary/request_queue.rb
Defined Under Namespace
Classes: Target
Instance Attribute Summary collapse
-
#between ⇒ Object
readonly
Returns the value of attribute between.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
-
#queue_suffix ⇒ Object
readonly
Returns the value of attribute queue_suffix.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#user_group ⇒ Object
readonly
Returns the value of attribute user_group.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(queue) ⇒ Sender
constructor
A new instance of Sender.
- #perform ⇒ Object
- #send_next_request ⇒ Object
- #session ⇒ Object
- #session_user ⇒ Object
-
#start(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') ⇒ Object
Send all requests, either directly or by schedule Note that the :between argument here represents the time between sending consecutive requests, whereas in RequestQueue#send_all it represents the time between starting consecutive queues.
Constructor Details
Instance Attribute Details
#between ⇒ Object (readonly)
Returns the value of attribute between.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def between @between end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def delay @delay end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def priority @priority end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def queue @queue end |
#queue_name ⇒ Object (readonly)
Returns the value of attribute queue_name.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def queue_name @queue_name end |
#queue_suffix ⇒ Object (readonly)
Returns the value of attribute queue_suffix.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def queue_suffix @queue_suffix end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def target @target end |
#user_group ⇒ Object (readonly)
Returns the value of attribute user_group.
94 95 96 |
# File 'lib/fragmentary/request_queue.rb', line 94 def user_group @user_group end |
Class Method Details
.jobs ⇒ Object
75 76 77 |
# File 'lib/fragmentary/request_queue.rb', line 75 def jobs ::Delayed::Job.where("(handler LIKE ?) OR (handler LIKE ?)", "--- !ruby/object:#{name} %", "--- !ruby/object:#{name}\n%") end |
Instance Method Details
#perform ⇒ Object
132 133 134 135 |
# File 'lib/fragmentary/request_queue.rb', line 132 def perform Rails.logger.info "\n***** Processing request queue for user_type '#{queue.user_type}'\n" @between ? send_next_request : send_all_requests end |
#send_next_request ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/fragmentary/request_queue.rb', line 137 def send_next_request if queue.size > 0 request = queue.next_request parameters = (request.parameters || {}).merge(:queue_suffix => queue_suffix) session.send_request(:method => request.method, :path => request.path, :parameters => parameters, :options => request.) end end |
#session ⇒ Object
107 108 109 |
# File 'lib/fragmentary/request_queue.rb', line 107 def session @session ||= InternalUserSession.new(@target.url, session_user) end |
#session_user ⇒ Object
103 104 105 |
# File 'lib/fragmentary/request_queue.rb', line 103 def session_user @session_user ||= Fragmentary::SessionUser.fetch(queue.user_type, user_group) end |
#start(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') ⇒ Object
Send all requests, either directly or by schedule Note that the :between argument here represents the time between sending consecutive requests, whereas in RequestQueue#send_all it represents the time between starting consecutive queues. The :between argument here is deprecated. There is no :between value passed from RequestQueue.send_all to RequestQueue::Sender#start
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/fragmentary/request_queue.rb', line 115 def start(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') Rails.logger.info "\n***** Processing request queue for user_type '#{queue.user_type}'\n" @delay = delay @between = between @queue_suffix = queue_suffix @priority = priority @user_group = user_group if @delay or @between schedule_requests(@delay) # sending requests by schedule makes a copy of the sender and queue objects for # asynchronous execution, so we have to manually clear out the original queue. queue.clear else send_all_requests end end |