Class: CassandraQueue::Queue
- Inherits:
-
Object
- Object
- CassandraQueue::Queue
- Defined in:
- lib/cassandra-queue.rb
Class Method Summary collapse
-
.retrieve(qid, opts = {}) ⇒ Object
(also: get_queue, get)
Entry point for using a queue.
Instance Method Summary collapse
- #empty?(options = {}) ⇒ Boolean
-
#insert(payload, time = Time.now, options = {}) ⇒ Object
(also: #add)
Takes a payload, throws it on the queue, and returns the TimeUUID that was created for it.
-
#list(get_times = false, options = {}) ⇒ Object
(also: #list_queue, #queue)
Show the first 100 elements of the queue by default, for things such as failure recovery.
- #payloads(options = {}) ⇒ Object (also: #messages, #values)
-
#peek(get_time = false, options = {}) ⇒ Object
(also: #front, #get_first)
Show the first (oldest) element in the queue Returns payload [TimeUUID, payload] as a two element array.
- #pop(get_time = false, options = {}) ⇒ Object (also: #dequeue)
- #push(payload, options = {}) ⇒ Object (also: #enqueue)
-
#remove(timeUUID, options = {}) ⇒ Object
(also: #delete)
Removes a TimeUUID, and it’s payload, from the queue.
Class Method Details
.retrieve(qid, opts = {}) ⇒ Object Also known as: get_queue, get
Entry point for using a queue. Class method which will return you a queue object for that UUID
27 28 29 30 31 32 |
# File 'lib/cassandra-queue.rb', line 27 def self.retrieve(qid, opts = {}) string_queue = opts[:string_queue] || false keyspace = opts[:keyspace] || DEFAULT_KEYSPACE servers = opts[:servers] || DEFAULT_SERVERS QueueManager.queue(qid, string_queue, keyspace, servers) end |
Instance Method Details
#empty?(options = {}) ⇒ Boolean
76 77 78 |
# File 'lib/cassandra-queue.rb', line 76 def empty?( = {}) list(true, ).empty? end |
#insert(payload, time = Time.now, options = {}) ⇒ Object Also known as: add
Takes a payload, throws it on the queue, and returns the TimeUUID that was created for it
39 40 41 42 43 |
# File 'lib/cassandra-queue.rb', line 39 def insert(payload, time = Time.now, = {}) timeUUID = UUID.new(time) @client.insert(@queue_cf, @key, { timeUUID => payload }, ) timeUUID end |
#list(get_times = false, options = {}) ⇒ Object Also known as: list_queue, queue
Show the first 100 elements of the queue by default, for things such as failure recovery
61 62 63 64 |
# File 'lib/cassandra-queue.rb', line 61 def list(get_times = false, = {}) list = @client.get(@queue_cf, @key, ) get_times ? list : list.values end |
#payloads(options = {}) ⇒ Object Also known as: messages, values
69 70 71 |
# File 'lib/cassandra-queue.rb', line 69 def payloads( = {}) list(false, ) end |
#peek(get_time = false, options = {}) ⇒ Object Also known as: front, get_first
Show the first (oldest) element in the queue Returns payload [TimeUUID, payload] as a two element array
82 83 84 85 86 |
# File 'lib/cassandra-queue.rb', line 82 def peek(get_time = false, = {}) .merge(:count => 1) payload = @client.get(@queue_cf, @key, ).first payload && !get_time ? payload.last : payload end |
#pop(get_time = false, options = {}) ⇒ Object Also known as: dequeue
91 92 93 94 95 96 |
# File 'lib/cassandra-queue.rb', line 91 def pop(get_time = false, = {}) item = peek(true, ) return nil if item.nil? remove(item.first, ) get_time ? item : item.last end |
#push(payload, options = {}) ⇒ Object Also known as: enqueue
47 48 49 |
# File 'lib/cassandra-queue.rb', line 47 def push(payload, = {}) insert(payload, Time.now, ) end |
#remove(timeUUID, options = {}) ⇒ Object Also known as: delete
Removes a TimeUUID, and it’s payload, from the queue
54 55 56 |
# File 'lib/cassandra-queue.rb', line 54 def remove(timeUUID, = {}) @client.remove(@queue_cf, @key, timeUUID, ) end |