dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

I've been tasked with writing a daemon that will watch for new files in a given directory. When one appears, it will attempt to flock (non-blocking) the file. When it attains the lock, it will process it and delete it. (Flocking is ok because that's the agreed-upon API between the daemon and the application(s) that will be depositing files in this directory.)

My first question is if there's anything on CPAN for this. It's going to run on Solaris, so Win32::ChangeNotify isn't going to help. filechange.monitor also isn't helpful because it's part of a larger project. Mostly, I'm interested in prior art regarding the daemonic part.

The second question is how to test something like this. The daemon is going to run in the background, so should I just kick it off, run tests against it, verify its logs, then tear it down (a-la Apache::Test)? What have others done in this situation?

Replies are listed 'Best First'.
Re: Testing filesystem monitor
by bart (Canon) on Apr 11, 2005 at 20:40 UTC
    If you ask me, even ChangeNotify() is overkill, as every file is a new file, as you delete them after processing.

    So what would I do? Just loop through all the files, attempt to flock them in nonblocking mode, and if you find one, process it, and delete it. And then start again from the top.

    If you don't find one, just sleep a few seconds and try again.

Re: Testing filesystem monitor
by jonadab (Parson) on Apr 11, 2005 at 18:58 UTC
    Mostly, I'm interested in prior art regarding the daemonic part.

    Will Proc::Daemon help?

Re: Testing filesystem monitor
by Steve_p (Priest) on Apr 11, 2005 at 20:32 UTC

    I would guess that POE would be idea for doing this. You could probably surf the cookbook at the POE website for any examples that are already written.