our @EXPORT_OK = qw/watch/;
our $VERSION = '0.001';
-use Fcntl qw/O_WRONLY O_EXCL O_CREAT/;
+use Fcntl qw/:flock/;
use Linux::Inotify2;
use Log::Log4perl qw/get_logger/;
my ($name, $dir, $cb) = @_;
my $logger = get_logger;
$logger->debug("Taking job $name...");
- if (sysopen my $file, "$dir/$name/pidfile", O_WRONLY | O_EXCL | O_CREAT){
+ open my $file, ">>$dir/$name/meta.yml";
+ if (flock my $file, LOCK_EX|LOCK_NB){
$logger->debug("Successfully taken job $name, executing callback");
$cb->("$dir/$name");
} else {
$logger->debug("Job $name already taken");
}
+ close $file;
}
sub watch{