lib/qu/backend/memory.rb in qu-spec-0.1.2 vs lib/qu/backend/memory.rb in qu-spec-0.2.0

- old
+ new

@@ -55,10 +55,24 @@ @queues[payload.queue] << payload logger.debug { "Enqueued job #{payload}" } payload end + def delayed_push(time, payload) + payload.id = SimpleUUID::UUID.new.to_guid + payload.time = time + @queues[scheduled_queue_name(payload.klass)] << payload + logger.debug { "Enqueued delayed job #{payload}" } + payload + end + + def remove_delayed(klass, *args) + get_queue_by_name(scheduled_queue_name(klass)).delete_if do |payload| + payload.klass.to_s == klass.to_s && payload.args == args + end + end + def reserve(worker, options = {:block => true}) loop do worker.queues.each do |queue| logger.debug { "Reserving job in queue #{queue}" } return @queues[queue].shift unless @queues[queue].empty? @@ -91,9 +105,19 @@ end def get_queue_by_klass(klass) payload = Payload.new(:klass => klass) get_queue_by_name(payload.queue) + end + + def get_schedule_by_klass(klass) + get_queue_by_name(scheduled_queue_name(klass)) + end + + private + + def scheduled_queue_name(klass) + "#{klass.to_s}_scheduled" end end end end