Class: Fragmentary::RequestQueue::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/fragmentary/request_queue.rb

Defined Under Namespace

Classes: Target

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Sender

Returns a new instance of Sender.



96
97
98
99
100
101
# File 'lib/fragmentary/request_queue.rb', line 96

def initialize(queue)
  @queue = queue
  @target = Target.new(queue.host_root_url)
  @user_group = 'default'
  @queue_name = @target.queue_name
end

Instance Attribute Details

#betweenObject (readonly)

Returns the value of attribute between.



94
95
96
# File 'lib/fragmentary/request_queue.rb', line 94

def between
  @between
end

#delayObject (readonly)

Returns the value of attribute delay.



94
95
96
# File 'lib/fragmentary/request_queue.rb', line 94

def delay
  @delay
end

#priorityObject (readonly)

Returns the value of attribute priority.



94
95
96
# File 'lib/fragmentary/request_queue.rb', line 94

def priority
  @priority
end

#queueObject (readonly)

Returns the value of attribute queue.



94
95
96
# File 'lib/fragmentary/request_queue.rb', line 94

def queue
  @queue
end

#queue_nameObject (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_suffixObject (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

#targetObject (readonly)

Returns the value of attribute target.



94
95
96
# File 'lib/fragmentary/request_queue.rb', line 94

def target
  @target
end

#user_groupObject (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

.jobsObject



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

#performObject



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_requestObject



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.options)
  end
end

#sessionObject



107
108
109
# File 'lib/fragmentary/request_queue.rb', line 107

def session
  @session ||= InternalUserSession.new(@target.url, session_user)
end

#session_userObject



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