Sha256: 95b2b3ef1d80fcbc1b8bb79721086629d5ee70136fbe133ae40695d7e92dafcf

Contents?: true

Size: 1 KB

Versions: 19

Compression:

Stored size: 1 KB

Contents

# This is a queue implementation for the queue service based on file systems
module DispatchRider
  module QueueServices
    class FileSystem < Base
      class Queue
        def initialize(path)
          FileUtils.mkdir_p(path)
          @path = path
        end

        def add(item)
          name_base = "#{@path}/#{Time.now.to_f}"
          File.open("#{name_base}.inprogress", "w"){ |f| f.write(item) }
          FileUtils.mv("#{name_base}.inprogress", "#{name_base}.ready")
        end

        def pop
          file_path = file_paths.first
          return nil unless file_path
          file_path_inflight = file_path.gsub(/\.ready$/, '.inflight')
          FileUtils.mv(file_path, file_path_inflight)
          File.new(file_path_inflight)
        end

        def remove(item)
          item.close
          File.unlink(item.path)
        end

        def size
          file_paths.size
        end

        private

        def file_paths
          Dir["#{@path}/*.ready"]
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dispatch-rider-1.0.3 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-1.0.2 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-1.0.1 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-1.0.0 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.7 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.6 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.5 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.4 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.3 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.2 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.1 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.2.0 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.1.2 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.1.1.1 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.1.0 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.0.7 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.0.5 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.0.4 lib/dispatch-rider/queue_services/file_system/queue.rb
dispatch-rider-0.0.3 lib/dispatch-rider/queue_services/file_system/queue.rb