From a869ed04351d3ea1cc7fd54b822935491fec5b5a Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 26 Nov 2007 15:40:57 -0600 Subject: [PATCH] MARC import: part 5 of large file support Staging job now gets moved to background so that it does not get killed if it takes longer than the Apache timeout. Added AJAX monitoring of job status. Signed-off-by: Joshua Ferraro --- C4/BackgroundJob.pm | 38 ++----- .../prog/en/includes/background-job.inc | 82 ++++++++++++++ .../en/modules/tools/stage-marc-import.tmpl | 12 ++- tools/background-job-progress.pl | 56 ++++++++++ tools/stage-marc-import.pl | 101 +++++++++++++----- tools/upload-file-progress.pl | 1 - 6 files changed, 230 insertions(+), 60 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc create mode 100755 tools/background-job-progress.pl diff --git a/C4/BackgroundJob.pm b/C4/BackgroundJob.pm index 9f3acff9f9..22baaae104 100644 --- a/C4/BackgroundJob.pm +++ b/C4/BackgroundJob.pm @@ -105,19 +105,7 @@ sub _serialize { my $prefix = "job_" . $self->{'jobID'}; my $session = get_session($self->{'sessionID'}); - $session->param("$prefix.name", $self->{'name'}); - $session->param("$prefix.invoker", $self->{'invoker'}); - $session->param("$prefix.size", $self->{'size'}); - $session->param("$prefix.progress", $self->{'size'}); - $session->param("$prefix.status", $self->{'size'}); - if (exists $self->{'results'}) { - my @keys = (); - foreach my $key (keys %{ $self->{'results'} }) { - $session->param("$prefix.results.$key", $self->{'results'}->{$key}); - push @keys, $key; - } - $session->param("$prefix.results_keys", join("\t", @keys)); - } + $session->param($prefix, $self); $session->flush(); } @@ -135,7 +123,7 @@ Read-only accessor for job ID. sub id { my $self = shift; - return $self->{'id'}; + return $self->{'jobID'}; } =head2 name @@ -264,8 +252,8 @@ the results of the job. sub finish { my $self = shift; my $results_hashref = shift; - my $self->{'status'} = 'completed'; - my $self->{'results'} = $results_hashref; + $self->{'status'} = 'completed'; + $self->{'results'} = $results_hashref; $self->_serialize(); } @@ -309,24 +297,10 @@ sub fetch { my $session = get_session($sessionID); my $prefix = "job_$jobID"; - unless (defined $session->param("$prefix.name")) { + unless (defined $session->param($prefix)) { return undef; } - my $self = {}; - - $self->{'name'} = $session->param("$prefix.name"); - $self->{'status'} = $session->param("$prefix.status"); - $self->{'invoker'} = $session->param("$prefix.invoker"); - $self->{'size'} = $session->param("$prefix.size"); - $self->{'progress'} = $session->param("$prefix.progress"); - if (defined(my $keys = $session->param("$prefix.results_keys"))) { - my @keys = split /\t/, $keys; - $self->{'results'} = {}; - foreach my $key (@keys) { - $self->{'results'}->{$key} = $session->param("$prefix.results.$key"); - } - } - + my $self = $session->param($prefix); bless $self, $class; return $self; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc new file mode 100644 index 0000000000..fe626ba202 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc @@ -0,0 +1,82 @@ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tmpl index aae7aa3618..f284f33223 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tmpl @@ -2,6 +2,7 @@ Koha › Tools › Stage MARC Records For Import +