Class: Workerholic::Queue
- Inherits:
-
Object
- Object
- Workerholic::Queue
- Defined in:
- lib/workerholic/queue.rb
Overview
Handles background job enqueueing/dequeuing functionality
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(serialized_job) ⇒ Object
-
#initialize(name = 'workerholic:queue:main') ⇒ Queue
constructor
A new instance of Queue.
- #size ⇒ Object
Constructor Details
#initialize(name = 'workerholic:queue:main') ⇒ Queue
Returns a new instance of Queue.
6 7 8 9 10 |
# File 'lib/workerholic/queue.rb', line 6 def initialize(name = 'workerholic:queue:main') @storage = Storage::RedisWrapper.new @name = name @logger = LogManager.new end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/workerholic/queue.rb', line 4 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/workerholic/queue.rb', line 4 def name @name end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
4 5 6 |
# File 'lib/workerholic/queue.rb', line 4 def storage @storage end |
Instance Method Details
#dequeue ⇒ Object
17 18 19 20 |
# File 'lib/workerholic/queue.rb', line 17 def dequeue job_info = storage.pop(name) job_info.last if job_info end |
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/workerholic/queue.rb', line 22 def empty? storage.list_length(name) == 0 end |
#enqueue(serialized_job) ⇒ Object
12 13 14 15 |
# File 'lib/workerholic/queue.rb', line 12 def enqueue(serialized_job) storage.push(name, serialized_job) # logger.info("Your job was placed in the #{name} queue on #{Time.now}.") end |
#size ⇒ Object
26 27 28 |
# File 'lib/workerholic/queue.rb', line 26 def size storage.list_length(name) end |