Project

broom

0.0
No commit activity in last 3 years
No release in over 3 years
A small module for watching a directory for new files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Broom

A simple module to help monitor a directory for new files and perform an action on each new file. Broom periodically sweeps a directory, caching each file and its last modification time. After each sweep, Broom iterates through the cache and yields only the files that have a current modification time that matches the cached modification time. In the event of an error, Broom gracefully sweeps the file to a failure dustpan. Else, the file is swept to a success dustpan.

Broom depends on the following directory structure, which can be modified using the 'success_dir' and 'failure_dir' options.

/path/to/directory
/path/to/directory/_success
/path/to/directory/_failure

Installation

gem install broom

Examples

Broom.sweep('/dropbox') do |path, dirname, basename, extname|
  Resque.enqueue(Job, "#{dirname}/_success/#{basename}")
end

threads = []

threads << Thread.new do
  Broom.sweep('/foo') do |path, dirname, basename, extname|
    # do something
  end
end

threads << Thread.new do
  Broom.sweep('/bar') do |path, dirname, basename, extname|
    # do something
  end
end

threads.each { |x| x.join }