mongodb_queue
MongoDB based work queue written in Ruby. Supports multiple queues.
Installation
Add this line to your application's Gemfile:
gem 'mongodb_queue'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mongodb_queue
Usage
require 'mongodb_queue'
queue = MongoDBQueue::MongoDBQueue.new({address: 'localhost', port: 27017, database: 'test-db', collection: 'test-queue'})
person = {name: 'John', age: 32, id: '123456789'}
person2 = {name: 'Jane', age: 29, id: '123456789'}
queue.enqueue(person)
queued_person = queue.dequeue
queue.enqueue(person, :friends)
friend = queue.dequeue(:friends)
queue.enqueue(person, [:faculty, :staff])
faculty_member = queue.dequeue(:faculty)
staff_member = queue.dequeue(:staff)
@queue.enqueue(person, :faculty, {unique_field: :id_num})
@queue.enqueue(person2, :faculty, {unique_field: :id_num})
faculty_member = queue.dequeue(:faculty)
queue.enqueue(person, :faculty)
faculty_member = queue.dequeue(:faculty, {delete: true})
queue.enqueue(person)
faculty_member = queue.dequeue(MongoDBQueue::DEFAULT_QUEUE, {status: :processing})
queue.remove_all([:success, :error])
queue.requeue_timed_out(300)
queue.requeue_timed_out(300, :processing)
queue.unset_all([:success], :name)
queue.destroy
Sample MongoDB Document
This is a document that has been added to 2 queues - test_queue and test_queue2. It has already been dequeued from test_queue
{
"_id" : ObjectId("549b1678b83b50d6bf000001"),
"name" : "John",
"age" : 32,
"id_num" : "123456789",
"queue" : [
{
"name" : "test_queue",
"status" : "dequeued",
"queued_timestamp" : ISODate("2014-12-24T19:39:36.051Z"),
"dequeued_timestamp" : ISODate("2014-12-24T19:39:36.053Z")
},
{
"name" : "test_queue2",
"status" : "queued",
"queued_timestamp" : ISODate("2014-12-24T19:39:55.052Z")
}
]
}
Contributing
- Fork it ( https://github.com/dashingrocket/mongodb_queue/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
Copyright 2014 Dashing Rocket, Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.