App::MadEye::Plugin::Check::Flock - lock.


App-MadEye documentation Contained in the App-MadEye distribution.

Index


Code Index:

NAME

Top

App::MadEye::Plugin::Check::Flock - lock.

SYNOPSIS

Top

    - module: Check::Flock
      config:
        file: /var/run/madeye

SCHEMA

Top

    type: map
    mapping:
        file:
            required: yes
            type: str

AUTHOR

Top

Tokuhiro Matsuno

SEE ALSO

Top

App::MadEye


App-MadEye documentation Contained in the App-MadEye distribution.

package App::MadEye::Plugin::Check::Flock;
use strict;
use warnings;
use base qw/App::MadEye::Plugin::Base/;
use LWP::UserAgent;
use Fcntl ":flock";

sub check : Hook {
    my ($self, $context, $args) = @_;

    my $file_name = $self->config->{config}->{file} or die "missing file";
    open $self->{lock_fh} , '>' , $file_name or die $!;
    my $status = flock( $self->{lock_fh}, LOCK_EX|LOCK_NB ) or die "cannot get the lock";
}

sub after_run_jobs : Hook {
    my ($self, $context, $args) = @_;

    close($self->{lock_fh}); # release lock
}

1;
__END__