Class: Fragmentary::RequestQueue
- Inherits:
-
Object
- Object
- Fragmentary::RequestQueue
- Defined in:
- lib/fragmentary/request_queue.rb
Defined Under Namespace
Classes: Sender
Instance Attribute Summary collapse
-
#host_root_url ⇒ Object
readonly
Returns the value of attribute host_root_url.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#user_type ⇒ Object
readonly
Returns the value of attribute user_type.
Class Method Summary collapse
- .all ⇒ Object
- .send_all(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') ⇒ Object
Instance Method Summary collapse
- #<<(request) ⇒ Object
- #clear ⇒ Object
-
#initialize(user_type, host_root_url) ⇒ RequestQueue
constructor
A new instance of RequestQueue.
- #method_missing(method, *args, **kwargs) ⇒ Object
- #next_request ⇒ Object
- #remove_path(path) ⇒ Object
- #send(**kwargs) ⇒ Object
- #sender ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(user_type, host_root_url) ⇒ RequestQueue
Returns a new instance of RequestQueue.
27 28 29 30 31 32 33 34 35 |
# File 'lib/fragmentary/request_queue.rb', line 27 def initialize(user_type, host_root_url) @user_type = user_type # host_root_url represents where the queued *requests* are to be processed. For internal sessions it also represents where # the *queue* will be processed by delayed_job. For external requests, the queue will be processed by the host creating the # queue and the requests will be explicitly sent to the host_root_url. @host_root_url = host_root_url @requests = [] self.class.all << self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
68 69 70 |
# File 'lib/fragmentary/request_queue.rb', line 68 def method_missing(method, *args, **kwargs) sender.send(method, *args, **kwargs) end |
Instance Attribute Details
#host_root_url ⇒ Object (readonly)
Returns the value of attribute host_root_url.
25 26 27 |
# File 'lib/fragmentary/request_queue.rb', line 25 def host_root_url @host_root_url end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
25 26 27 |
# File 'lib/fragmentary/request_queue.rb', line 25 def requests @requests end |
#user_type ⇒ Object (readonly)
Returns the value of attribute user_type.
25 26 27 |
# File 'lib/fragmentary/request_queue.rb', line 25 def user_type @user_type end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/fragmentary/request_queue.rb', line 5 def self.all @@all ||= [] end |
.send_all(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fragmentary/request_queue.rb', line 9 def self.send_all(delay: nil, between: nil, queue_suffix: '', priority: 0, user_group: 'default') unless delay or between all.each{|q| q.start(queue_suffix: queue_suffix, priority: priority, user_group: user_group)} else delay ||= 0.seconds between ||= 0.seconds unless delay.is_a? ActiveSupport::Duration raise TypeError, "Fragmentary::RequestQueue.send_all requires the keyword argument :delay to be of class ActiveSupport::Duration. The value provided is of class #{delay.class.name}." end unless between.is_a? ActiveSupport::Duration raise TypeError, "Fragmentary::RequestQueue.send_all requires the keyword argument :between to be of class ActiveSupport::Duration. The value provided is of class #{between.class.name}." end all.each{|q| q.start(delay: (delay += between), queue_suffix: queue_suffix, priority: priority, user_group: user_group)} end end |
Instance Method Details
#<<(request) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/fragmentary/request_queue.rb', line 37 def <<(request) unless @requests.find{|r| r == request} @requests << request end self end |
#clear ⇒ Object
52 53 54 |
# File 'lib/fragmentary/request_queue.rb', line 52 def clear @requests = [] end |
#next_request ⇒ Object
48 49 50 |
# File 'lib/fragmentary/request_queue.rb', line 48 def next_request @requests.shift end |
#remove_path(path) ⇒ Object
56 57 58 |
# File 'lib/fragmentary/request_queue.rb', line 56 def remove_path(path) requests.delete_if{|r| r.path == path} end |
#send(**kwargs) ⇒ Object
64 65 66 |
# File 'lib/fragmentary/request_queue.rb', line 64 def send(**kwargs) sender.start(**kwargs) end |
#sender ⇒ Object
60 61 62 |
# File 'lib/fragmentary/request_queue.rb', line 60 def sender @sender ||= Sender.new(self) end |
#size ⇒ Object
44 45 46 |
# File 'lib/fragmentary/request_queue.rb', line 44 def size @requests.size end |