Class: TaskQueue
- Inherits:
-
Object
- Object
- TaskQueue
- Defined in:
- lib/yodel/task_queue/task_queue.rb
Constant Summary collapse
- MAX_TASK_ATTEMPTS =
5
Instance Method Summary collapse
- #conditions ⇒ Object
-
#initialize(immediate) ⇒ TaskQueue
constructor
A new instance of TaskQueue.
- #pop ⇒ Object
Constructor Details
#initialize(immediate) ⇒ TaskQueue
Returns a new instance of TaskQueue.
11 12 13 |
# File 'lib/yodel/task_queue/task_queue.rb', line 11 def initialize(immediate) @immediate = immediate end |
Instance Method Details
#conditions ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/yodel/task_queue/task_queue.rb', line 32 def conditions if @immediate query = {due: nil} else query = {due: {'$lte' => Time.now.utc}} end query.merge(locked: nil, attempts: {'$lt' => MAX_TASK_ATTEMPTS}) end |
#pop ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/yodel/task_queue/task_queue.rb', line 15 def pop = {query: conditions, update: {'$set' => {locked: Time.now}}, sort: ['created_at', 1]} document = Task.collection.find_and_modify() return nil if document.nil? site = Site.find(document['_site_id']) # FIXME: write error to log here if site.nil? Task.collection.remove(_id: document['_id']) return nil end Task.new(site, document) rescue Mongo::OperationFailure return nil end |