More work on the scheduler

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Chris Cormack 2007-10-29 13:21:31 -05:00 committed by Joshua Ferraro
parent 1a9af39d1c
commit ea899bc559
2 changed files with 46 additions and 21 deletions

View File

@ -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);
}

View File

@ -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 );