class Bricolage::FileTaskQueue
Public Class Methods
new(path)
click to toggle source
Calls superclass method
Bricolage::TaskQueue::new
# File lib/bricolage/taskqueue.rb, line 82 def initialize(path) super() @path = path end
restore_if_exist(path)
click to toggle source
# File lib/bricolage/taskqueue.rb, line 76 def FileTaskQueue.restore_if_exist(path) q = new(path) q.restore if q.queued? q end
Public Instance Methods
lock()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 120 def lock FileUtils.touch lock_file_path end
lock_file_path()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 128 def lock_file_path Pathname.new("#{@path}.LOCK") end
locked?()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 116 def locked? lock_file_path.exist? end
queued?()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 87 def queued? @path.exist? end
restore()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 110 def restore File.foreach(@path) do |line| enq JobTask.deserialize(line) end end
save()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 91 def save if empty? @path.unlink if @path.exist? return end FileUtils.mkdir_p @path.dirname tmpname = "#{@path}.tmp.#{Process.pid}" begin File.open(tmpname, 'w') {|f| each do |task| f.puts task.serialize end } File.rename tmpname, @path ensure FileUtils.rm_f tmpname end end
unlock()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 124 def unlock FileUtils.rm_f lock_file_path end
unlock_help()
click to toggle source
# File lib/bricolage/taskqueue.rb, line 132 def unlock_help "remove the file: #{lock_file_path}" end