| 1 |
Schedule::Cron |
| 2 |
============== |
| 3 |
|
| 4 |
This module provides a simple but complete cron like scheduler. I.e |
| 5 |
this modules can be used for periodically executing Perl subroutines. |
| 6 |
The dates and parameters for the subroutines to be called are |
| 7 |
specified with a format known as crontab entry (see manpage crontab(5) |
| 8 |
or documentation of Schedule::Cron). |
| 9 |
|
| 10 |
The philosophy behind Schedule::Cron is to call subroutines |
| 11 |
periodically from within one single Perl program instead of letting |
| 12 |
cron trigger several (possibly different) Perl scripts. Everything |
| 13 |
under one roof. Furthermore Schedule::Cron provides mechanism to |
| 14 |
create crontab entries dynamically, which isn't that easy with cron. |
| 15 |
|
| 16 |
Schedule::Cron knows about all extensions (well, at least all |
| 17 |
extensions I'm aware of, i.e those of the so called "Vixie" cron) for |
| 18 |
crontab entries like ranges including 'steps', specification of month |
| 19 |
and days of the week by name or coexistence of lists and ranges in the |
| 20 |
same field. And even a bit more (like lists and ranges with symbolic |
| 21 |
names). |
| 22 |
|
| 23 |
This module is rather effective concerning system load. It calculates |
| 24 |
the execution dates in advance and will sleep until those dates are |
| 25 |
reached (and wont wake up every minute to check for execution like |
| 26 |
cron). However, it relies on the accuracy of your sleep() system call. |
| 27 |
|
| 28 |
EXAMPLES |
| 29 |
-------- |
| 30 |
|
| 31 |
* Minimalistic: |
| 32 |
|
| 33 |
use Schedule::Cron; |
| 34 |
|
| 35 |
my $dispatcher = sub { print "Time to start...\n"}; |
| 36 |
my $cron = new Schedule::Cron($dispatcher); |
| 37 |
|
| 38 |
$cron->add_entry("0 7 * * *"); |
| 39 |
$cron->run; # Runs forever... |
| 40 |
|
| 41 |
* A bit more complex: |
| 42 |
|
| 43 |
use Schedule::Cron; |
| 44 |
|
| 45 |
my $cron = new Schedule::Cron( sub { print "@_","\n" }, |
| 46 |
file => "check_links.sched", |
| 47 |
eval => 1); |
| 48 |
|
| 49 |
sub check_links { |
| 50 |
my $args = shift; |
| 51 |
print "URL: ",$args->{url},"\n"; |
| 52 |
print "Depth: ",$args->{depth},"\n"; |
| 53 |
} |
| 54 |
|
| 55 |
$cron->add_entry("0-40/5,55 3,22 * Jan-Nov Fri", |
| 56 |
{ sub => \&check_links, |
| 57 |
args => [ { url => "http://www.consol.de", |
| 58 |
depth => 2 } ], |
| 59 |
eval => 0 }); |
| 60 |
# ... add more .... |
| 61 |
$cron->run(detach=>1,pid_file=>"/var/run/checker.pid"); |
| 62 |
# ... continue ... |
| 63 |
|
| 64 |
* simple cron replacement (for a single crontab file): |
| 65 |
|
| 66 |
use Schedule::Cron; |
| 67 |
my $cron = new Schedule::Cron(sub { system(shift) }, |
| 68 |
file => "/var/spool/crontab.perl"); |
| 69 |
$cron->run(); |
| 70 |
|
| 71 |
PREREQUISITES |
| 72 |
------------- |
| 73 |
|
| 74 |
In order to install and use this package you will need Perl version |
| 75 |
5.005 or better. Furthermore you need the module Time::ParseDate |
| 76 |
(contained in the Time-modules-xx.xxxxx) available on CPAN. |
| 77 |
|
| 78 |
You need a fork()-aware Perl for dispatching the cron jobs. This might |
| 79 |
change in the future. On systems without a fork() system call you can |
| 80 |
use the 'nofork' option to run your jobs within the current process. |
| 81 |
|
| 82 |
OS-DEPENDENCIES |
| 83 |
--------------- |
| 84 |
|
| 85 |
Schedule::Cron was tested on a Redhat Linux-Box, but it should work on |
| 86 |
any UNIX Box. In depends on some original UNIX system calls for |
| 87 |
starting jobs and detaching itself to the background: |
| 88 |
|
| 89 |
* It uses fork() for starting jobs |
| 90 |
* For detaching it uses either setsid (POSIX) or the ioctl call |
| 91 |
TIOCNOTTY |
| 92 |
|
| 93 |
If the system calls mentioned above are not available (which should |
| 94 |
hapen nowadays only under rare circumstances), you can still use the |
| 95 |
'nofork' option to run all jobs within a single process/thread. Please |
| 96 |
refer to the documentation for further reading. |
| 97 |
|
| 98 |
INSTALLATION |
| 99 |
------------ |
| 100 |
|
| 101 |
Installation can be done the old fashioned way |
| 102 |
|
| 103 |
perl Makefile.PL |
| 104 |
make |
| 105 |
make test |
| 106 |
make install |
| 107 |
|
| 108 |
See the documentation for Schedule::Cron for a detailed description |
| 109 |
and further usage examples. |
| 110 |
|
| 111 |
REPORTING BUGS |
| 112 |
-------------- |
| 113 |
|
| 114 |
If you meet a bug (say hello to it ;-), open a ticket at |
| 115 |
https://rt.cpan.org/Ticket/Create.html?Queue=Schedule-Cron. |
| 116 |
|
| 117 |
In addition of a problem description, please add a short description |
| 118 |
of you OS, your Perl version and the version of Time::ParseDate you |
| 119 |
are using. If some of the provided tests fail, include the output of |
| 120 |
'make test TEST_VERBOSE=1' as well. |
| 121 |
|
| 122 |
If you suspect, that the date calculation of the next execution time |
| 123 |
is buggy, please use the following interactive command to generate a |
| 124 |
bug report. |
| 125 |
|
| 126 |
perl -MSchedule::Cron -e 'bug Schedule::Cron' |
| 127 |
|
| 128 |
You will be asked for a reference time (default: the current time), a |
| 129 |
crontab date pattern (with five columns) and the expected next |
| 130 |
execution date (relative to the reference time). The dates can be |
| 131 |
specified in a format understood by 'parsedate' from Time::ParseDate |
| 132 |
(like 'now + 5 days'). Please include the output of this command. |
| 133 |
|
| 134 |
REPOSITORY |
| 135 |
---------- |
| 136 |
|
| 137 |
Schedule::Cron's source is located at |
| 138 |
https://github.com/rhuss/schedule-cron Please feel free to send me |
| 139 |
pull requests if they apply to the license below. Also, don't forget |
| 140 |
documentation and tests. |
| 141 |
|
| 142 |
Please note also, that the active development for this module has been |
| 143 |
stopped since it is considered to be feature complete. Bugs and minor |
| 144 |
(external) additions will be added from time to time, though. |
| 145 |
|
| 146 |
COPYRIGHT AND LICENSE |
| 147 |
--------------------- |
| 148 |
|
| 149 |
Copyright (c) 1999-2013 Roland Huß. |
| 150 |
|
| 151 |
Copyright (c) 2022-2023 Nicholas Hubbard. |
| 152 |
|
| 153 |
This library is free software; you can redistribute it and/or modify |
| 154 |
it under the same terms as Perl itself. |
| 155 |
|
| 156 |
Enjoy it... |
| 157 |
...roland ([email protected]) |