Archer::Plugin::Flock - do not run two process in the same time.


Archer documentation Contained in the Archer distribution.

Index


Code Index:

NAME

Top

Archer::Plugin::Flock - do not run two process in the same time.

SYNOPSIS

Top

  - module: Flock
    config:
      file: /tmp/archer.lock

AUTHORS

Top

Tokuhiro Matsuno.


Archer documentation Contained in the Archer distribution.

package Archer::Plugin::Flock;
use strict;
use warnings;
use base qw/Archer::Plugin/;
use Fcntl ":flock";

sub run {
    my ($self, $context) = @_;

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

    $context->{__PACKAGE__} = $fh; # do not close the lock file :)
}

1;
__END__