From ea899bc55933cd74e4665d70b1c48cab82cd1257 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 29 Oct 2007 13:21:31 -0500 Subject: [PATCH] More work on the scheduler Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Scheduler.pm | 26 +++++++++++++++++++------- tools/scheduler.pl | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/C4/Scheduler.pm b/C4/Scheduler.pm index 961df0eb27..3a608e000a 100644 --- a/C4/Scheduler.pm +++ b/C4/Scheduler.pm @@ -29,7 +29,7 @@ $VERSION = 0.01; @ISA = qw(Exporter); @EXPORT = - qw(get_jobs get_job add_job remove_job); + qw(get_jobs get_at_jobs get_at_job add_at_job remove_at_job); =head1 NAME @@ -55,33 +55,45 @@ This will return all scheduled jobs =cut sub get_jobs { + my $jobs = get_at_jobs(); +# add call to get cron jobs here too + return ($jobs); +} + +=item get_at_jobs(); + +This will return all At scheduled jobs + +=cut + +sub get_at_jobs { my %jobs = Schedule::At::getJobs(); return (\%jobs); } -=item get_job($id) +=item get_at_job($id) -This will return the job with the given id +This will return the At job with the given id =cut -sub get_job { +sub get_at_job { my ($id)=@_; my %jobs = chedule::At::getJobs(JOBID => $id); } -=item add_job ($time,$command) +=item add_at_job ($time,$command) Given a timestamp and a command this will schedule the job to run at that time =cut -sub add_job { +sub add_at_job { my ($time,$command) = @_; Schedule::At::add(TIME => $time, COMMAND => $command, TAG => $command); } -sub remove_job { +sub remove_at_job { my ($jobid)=@_; Schedule::At::remove(JOBID => $jobid); } diff --git a/tools/scheduler.pl b/tools/scheduler.pl index 4d655803cc..b91c341e54 100755 --- a/tools/scheduler.pl +++ b/tools/scheduler.pl @@ -18,6 +18,7 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +use C4::Context; use C4::Scheduler; use C4::Reports; use C4::Auth; @@ -25,44 +26,56 @@ use CGI; use C4::Output; my $input = new CGI; + +my $base = C4::Context->config('intranetdir'); +my $command = "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; ".$base."/tools/runreport.pl $report $format $email"; + my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { - template_name => "tools/scheduler.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); + template_name => "tools/scheduler.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { editcatalogue => 1 }, + debug => 1, + } + ); my $mode=$input->param('mode'); + if ($mode eq 'job_add') { my $startday = $input->param('startday'); my $startmonth = $input->param('startmonth'); my $startyear = $input->param('startyear'); my $starttime = $input->param('starttime'); + my $recurring = $input->param('recurring'); $starttime =~ s/\://g; my $start = $startyear . $startmonth . $startday . $starttime; my $report=$input->param('report'); my $format=$input->param('format'); my $email=$input->param('email'); - my $base = "/nzkoha/intranet"; # EDIT THIS - my $command = "EXPORT KOHA_CONF=\"/nzkoha/etc/koha-kapiti.conf\"; ".$base."/tools/runreport.pl $report $format $email"; # EDIT THIS - add_job($start,$command); + if ($recurring){ + my $frequency = $input->param('frequency'); + add_cron_job($start,$command); + } + else { + add_at_job($start,$command); + } } if ($mode eq 'job_change'){ my $jobid = $input->param('jobid'); if ($input->param('delete')){ - remove_job($jobid); + remove_at_job($jobid); } } + my $jobs = get_jobs(); my @jobloop; foreach my $job (values %$jobs) { - push @jobloop,$job; - } + push @jobloop,$job; +} + @jobloop = sort {$a->{TIME} cmp $b->{TIME}} @jobloop; my $reports = get_saved_reports(); $template->param( 'savedreports' => $reports ); -- 2.39.5