App-Cronjob
view release on metacpan or search on metacpan
1.200000 2013-04-28 19:43:58 America/New_York
locking is now done with flock, not O_CREAT|O_EXCL (much of this
work by Mark Jason Dominus)
there are now two error types: lockfile (can't create the file) and
lock (can't get a lock on it)
1.102311 2010-11-02 17:09:23 America/New_York
lockfile now includes cronjob's pid
"can't locked, already locked" message now includes lockfile name
1.102310 2010-08-19 12:40:51 America/New_York
add an Auto-Submitted: auto-generated header (RFC 3834)
documentation typos fixed (thanks, chromatic)
1.101660 2010-06-15 17:01:46 America/New_York
added some more documentation to cronjob
1.101230 2010-05-03 17:32:03 America/New_York
allow A-Z and _ in jobname (requested by AVAR
bin/cronjob view on Meta::CPAN
#pod
#pod In other words, if you specify a C<--jobname> option, that will be used for
#pod naming the lockfile. This lets you force otherwise unrelated cronjobs to block
#pod each other. If you don't provide a job name, one is created by hashing the
#pod subject (of the report to send) or, failing that, the command itself. The
#pod hashing is a simple measure to prevent long or metacharacter-ridden filenames.
#pod
#pod The lockfile will contain information about the process that has the lock,
#pod including when it was begun.
#pod
#pod By default, all jobs are locked and failure to acquire a lock causes immediate
#pod failure of the cronjob. A failure report will be sent. To suppress failure
#pod reports in the event of lock failure, pass C<--ignore-errors lock> to the
#pod command. To skip locking, pass C<--no-lock>.
#pod
#pod Note that ignoring C<lock> failures only ignores failure to C<flock> the
#pod lockfile. If the file can't even be created, an error will still be reported.
#pod It will be of type C<lockfile>, and can be ignored by adding another
#pod C<--ignore-errors> option for that type.
__END__
bin/cronjob view on Meta::CPAN
In other words, if you specify a C<--jobname> option, that will be used for
naming the lockfile. This lets you force otherwise unrelated cronjobs to block
each other. If you don't provide a job name, one is created by hashing the
subject (of the report to send) or, failing that, the command itself. The
hashing is a simple measure to prevent long or metacharacter-ridden filenames.
The lockfile will contain information about the process that has the lock,
including when it was begun.
By default, all jobs are locked and failure to acquire a lock causes immediate
failure of the cronjob. A failure report will be sent. To suppress failure
reports in the event of lock failure, pass C<--ignore-errors lock> to the
command. To skip locking, pass C<--no-lock>.
Note that ignoring C<lock> failures only ignores failure to C<flock> the
lockfile. If the file can't even be created, an error will still be reported.
It will be of type C<lockfile>, and can be ignored by adding another
C<--ignore-errors> option for that type.
=head1 PERL VERSION
lib/App/Cronjob.pm view on Meta::CPAN
);
my $lock_flags = LOCK_EX | LOCK_NB;
unless (flock $lock_fh, $lock_flags) {
my $error = $!;
my $mtime = (stat $lock_fh)[9];
my $stamp = scalar localtime $mtime;
die App::Cronjob::Exception->new(
lock => "can't lock; $!; lockfile created $stamp",
{ locked_since => $mtime },
);
}
printf $lock_fh "pid %s running %s\nstarted at %s\n",
$$, $opt->{command}, scalar localtime $^T;
$got_lock = 1;
}
$logger->log([ 'trying to run %s', $opt->{command} ]);
lib/App/Cronjob.pm view on Meta::CPAN
};
exit 0 if $okay;
my $err = $@;
if (eval { $err->isa('App::Cronjob::Exception'); }) {
unless (
grep { $err->{type} and $_ eq $err->{type} } @{$opt->{ignore_errors}}
) {
if ($err->{type} eq "lock" && $opt->{temp_ignore_lock_errors}) {
my $age = time() - $err->{extra}{locked_since};
exit 0 if $age <= $opt->{temp_ignore_lock_errors};
}
send_cronjob_report({
is_fail => 1,
output => \$err->{text},
extra_headers => \@extra_headers,
});
}
exit 0;
( run in 0.503 second using v1.01-cache-2.11-cpan-49f99fa48dc )