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