Schedule::Advisory

An advisory job scheduler, where each job has a specific run frequency, or interval
Download

Schedule::Advisory Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • P. Kent
  • Publisher web site:
  • http://search.cpan.org/~pkent/

Schedule::Advisory Tags


Schedule::Advisory Description

An advisory job scheduler, where each job has a specific run frequency, or interval Schedule::Advisory is a Perl module that implements a scheduler for a set of jobs, where each job has a given run frequency or period - i.e. it should run once every so-many seconds. This module can determine which job should run next, and tells the caller which job it has chosen and how long (if at all) the caller needs to wait before starting the job. Note that this module does not sleep() for you, or invoke the job itself - those tasks are left to the caller, because the caller knows how it should best invoke a job (e.g. dispatch table, conditional branch, fork a worker process, ...), and if there are other delays to be accounted for before starting the job. This is why it's an "advisory" scheduler - it doesn't enforce a schedule itself.See "ALGORITHM" for a description of how the scheduler chooses jobs.You may add and remove jobs at any time. Each job has a unique ID string which is used to refer to the job. You may alter the run frequency at any time. You can also retrieve a list of all job IDs in the object, and timing information for each.The module also has a facility for spreading jobs out so that they don't all get scheduled at once, which is especially relevant if you have many jobs with the same period. The module Set::Partition::SimilarValues is used, if available, to help this facility generally work better.You may optionally store some "userdata" against each job. This userdata may be any single value (a string, number, hash reference, array reference, etc.) and can hold any data associated with the job. You may wish to use this facility if the caller doesn't have access to data required to complete the job. Userdata can be fetched, updated, or deleted at any time.High Resolution TimeAlthough it's not required by this module, it's recommended that you install Time::HiRes on your system. It provides sleep() and time() functions which have higher resolution and hence provide better accuracy for scheduling, although that's especially relevant when the interval between jobs is of the order of seconds instead of hours.The package global $Schedule::Advisory::FoundTimeHiRes is set to 1 if Time::HiRes was loaded, 0 otherwise.SYNOPSIS use Schedule::Advisory; # you may also wish to use Time::HiRes; for a high-resolution sleep() my $sched = new Schedule::Advisory(); $sched->add('foo', 300, { 'colour' => 'red' }); $sched->add('bar', 320, 'some userdata'); $sched->add('qux', 3600); $sched->remove('qux'); $sched->update_runperiod('bar', 300); $sched->spread; my @list_of_ids = $sched->all_jobs; my ($lastrun, $nextrun, $period) = $sched->get_job_data('foo'); my $rv = $sched->get_userdata('foo'); $sched->update_userdata('foo', { 'colour' => 'blue' }); $sched->delete_userdata('bar'); while ($some_condition) { my ($job_id, $delay, $userdata) = $sched->next_job; if ($delay) { sleep($delay); } do_something_to_invoke_job( $job_id, $userdata ); } Requirements: · Perl


Schedule::Advisory Related Software