Module: Komrade::Queue

Extended by:
HttpHelpers, Queue
Included in:
Queue
Defined in:
lib/komrade-client/queue.rb

Constant Summary

Constants included from HttpHelpers

HttpHelpers::MAX_RETRY

Instance Method Summary collapse

Methods included from HttpHelpers

delete, get, http, make_request, post, put

Instance Method Details

#delete_allObject

Delete all of the jobs in a queue. Returns the count of the jobs that were deleted.

Slow operation.



49
50
51
52
53
# File 'lib/komrade-client/queue.rb', line 49

def delete_all
  log(:at => "delete-all") do
    post("/delete-all-jobs")
  end
end

#dequeue(opts = {}) ⇒ Object

The jobs that are returned will be locked in komrade. This ensures that no other komrade clients can view them. If you dequeue a job, it is your responsiblity to update the job. Updates to jobs include: heartbeat, fail, and delete.

There is no logging for dequeue since this method will be called frequently. Instead, logging should happen in the caller of dequeue to inform the stream that a job was locked.

Moderately fast operation.



31
32
33
34
# File 'lib/komrade-client/queue.rb', line 31

def dequeue(opts={})
  limit = opts[:limit] || 1
  get("/jobs?limit=#{limit}")
end

#enqueue(method, *args) ⇒ Object

Generates a UUID for the job and sends it to komrade.

Fast operation.



13
14
15
16
17
18
19
# File 'lib/komrade-client/queue.rb', line 13

def enqueue(method, *args)
  SecureRandom.uuid.tap do |id|
    log(:at => "enqueue-job", :id => id, :method => method) do
      put("/jobs/#{id}", method: method, args: args)
    end
  end
end

#remove(id) ⇒ Object

Idempotent call to delete a job from the queue.

Fast operation.



39
40
41
42
43
# File 'lib/komrade-client/queue.rb', line 39

def remove(id)
  log(:at => "remove-job", :id => id) do
    delete("/jobs/#{id}")
  end
end