Sha256: d45bc54db4baf91641dff82a5ba79c27419b3281dd2a126a241dbbd2f2682340
Contents?: true
Size: 987 Bytes
Versions: 7
Compression:
Stored size: 987 Bytes
Contents
# This adapter is designed for testing purposes. # # Features supported: # # named queues: yes # priority: no # ttr: no # # Additionally this queue can be inspeced with JobQueue.adapter.queue('name') # class JobQueue::TestAdapter def initialize(options = {}) @queues = {} end def put(string, queue, priority, ttr) @queues[queue] ||= [] @queues[queue] << string end def subscribe(error_report, cleanup_task, queue, &block) loop do begin if get_queue(queue).empty? sleep 0.1 else job = get_queue(queue).shift yield job end rescue => e error_report.call(job, e) end end end # Additional method for TestAdapter to allow easy queue inspection with # # JobQueue.adapter.queue('foo') # def queue(queue = 'default') get_queue(queue) end def queue_length(queue) @queues[queue].size end private def get_queue(queue) @queues[queue] || [] end end
Version data entries
7 entries across 7 versions & 2 rubygems