X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon%2FBase.pm;fp=lib%2FGruntmaster%2FDaemon%2FBase.pm;h=0000000000000000000000000000000000000000;hp=3f6416c858534d78b6e6a405ef64c72f4fe8fbe8;hb=ab436d78d4cbe271d15676e5dac7b757a30d9537;hpb=ddceb393c90f620dd194c22e5e85d8c9fe87ee34 diff --git a/lib/Gruntmaster/Daemon/Base.pm b/lib/Gruntmaster/Daemon/Base.pm deleted file mode 100644 index 3f6416c..0000000 --- a/lib/Gruntmaster/Daemon/Base.pm +++ /dev/null @@ -1,44 +0,0 @@ -package Gruntmaster::Daemon::Base; - -use 5.014000; -use strict; -use warnings; -use parent qw/Exporter/; -our @EXPORT_OK = qw/watch/; -our $VERSION = '0.001'; - -use Fcntl qw/:flock/; -use Linux::Inotify2; -use Log::Log4perl qw/get_logger/; - -################################################## - -sub process{ - my ($name, $dir, $cb) = @_; - my $logger = get_logger; - $logger->debug("Taking job $name..."); - open my $file, ">>$dir/$name/meta.yml"; - if (flock $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{ - my ($dir, $cb) = @_; - for (<$dir/*>) { - s,$dir/,,; - process $_, $dir, $cb; - } - - my $logger = Log::Log4perl->get_logger(__PACKAGE__); - my $inotify = Linux::Inotify2->new or $logger->logdie("Unable to create Linux::Inotify2 object: $!"); - $inotify->watch($dir, IN_MOVED_TO, sub { process $_[0]->name, $dir, $cb }) or $logger->logdie("Error watching $dir: $!"); - 1 while $inotify->poll; - $logger->logdie("Inotify polling stopped: $!"); -} - -1