[Koha-cvs] koha updater/updatedatabase misc/cronjobs/zebra... [rel_3_0]
paul poulain
paul at koha-fr.org
Wed Dec 20 17:46:00 CET 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: paul poulain <tipaul> 06/12/20 16:46:00
Modified files:
updater : updatedatabase
Added files:
misc/cronjobs : zebraqueue_start.pl
Log message:
ZEBRA update :
- adding a new table : when a biblio is added/modified/ deleted, an entry is entered in this table
- the zebraqueue_start.pl script read it & does the stuff.
code coming from head (tumer). it can be run every minut instead of once every day for dev_week code.
I just have commented the previous code (=real time update) in Biblio.pm, we will be able to reactivate it once indexdata fixes zebra update bug !
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/cronjobs/zebraqueue_start.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/updater/updatedatabase?cvsroot=koha&only_with_tag=rel_3_0&r1=1.157.2.39&r2=1.157.2.40
Patches:
Index: updater/updatedatabase
===================================================================
RCS file: /sources/koha/koha/updater/updatedatabase,v
retrieving revision 1.157.2.39
retrieving revision 1.157.2.40
diff -u -b -r1.157.2.39 -r1.157.2.40
--- updater/updatedatabase 20 Dec 2006 11:42:17 -0000 1.157.2.39
+++ updater/updatedatabase 20 Dec 2006 16:45:59 -0000 1.157.2.40
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# $Id: updatedatabase,v 1.157.2.39 2006/12/20 11:42:17 toins Exp $
+# $Id: updatedatabase,v 1.157.2.40 2006/12/20 16:45:59 tipaul Exp $
# Database Updater
# This script checks for required updates to the database.
@@ -212,6 +212,14 @@
PRIMARY KEY (`entry`)
)
",
+ zebraqueue => "(
+ `id` int NOT NULL auto_increment,
+ `biblio_auth_number` int NOT NULL,
+ `operation` char(20) NOT NULL,
+ `server` char(20) NOT NULL ,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1",
+
);
my %requirefields = (
@@ -2041,6 +2049,15 @@
exit;
# $Log: updatedatabase,v $
+# Revision 1.157.2.40 2006/12/20 16:45:59 tipaul
+# ZEBRA update :
+# - adding a new table : when a biblio is added/modified/ deleted, an entry is entered in this table
+# - the zebraqueue_start.pl script read it & does the stuff.
+#
+# code coming from head (tumer). it can be run every minut instead of once every day for dev_week code.
+#
+# I just have commented the previous code (=real time update) in Biblio.pm, we will be able to reactivate it once indexdata fixes zebra update bug !
+#
# Revision 1.157.2.39 2006/12/20 11:42:17 toins
# adding table "tags"
#
Index: misc/cronjobs/zebraqueue_start.pl
===================================================================
RCS file: misc/cronjobs/zebraqueue_start.pl
diff -N misc/cronjobs/zebraqueue_start.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ misc/cronjobs/zebraqueue_start.pl 20 Dec 2006 16:45:59 -0000 1.1.2.1
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+# script that starts the zebraquee
+# Written by TG on 01/08/2006
+use strict;
+
+
+use C4::Context;
+use C4::Biblio;
+use C4::AuthoritiesMarc;
+use XML::Simple;
+use utf8;
+### ZEBRA SERVER UPDATER
+##Uses its own database handle
+my $dbh=C4::Context->dbh;
+my $readsth=$dbh->prepare("select id,biblio_auth_number,operation,server from zebraqueue");
+my $delsth=$dbh->prepare("delete from zebraqueue where id =?");
+
+
+AGAIN:
+
+my $wait=C4::Context->preference('zebrawait') || 1;
+my $verbose = 0;
+
+my ($id,$biblionumber,$operation,$server,$marcxml);
+
+$readsth->execute;
+while (($id,$biblionumber,$operation,$server)=$readsth->fetchrow){
+ print "read in queue : $id : biblio $biblionumber for $operation on $server\n" if $verbose;
+ if ($server eq "biblioserver") {
+ my $marc =GetMarcBiblio($biblionumber);
+ $marcxml = $marc->as_xml_record() if $marc;
+ } elsif ($server eq "authorityserver") {
+ $marcxml =C4::AuthoritiesMarc::XMLgetauthority($dbh,$biblionumber);
+ }
+ if ($verbose) {
+ if ($marcxml) {
+ print "XML read : $marcxml\n" if $verbose;
+ } else {
+ print "unable to read MARCxml\n" if $verbose;
+ }
+ }
+
+ eval {
+ my $hashed=XMLin($marcxml);
+ }; ### is it a proper xml? broken xml may crash ZEBRA- slow but safe
+
+ if ($@){
+ warn $@;
+ ## Broken XML-- Should not reach here-- but if it does -lets protect ZEBRA
+ $delsth->execute($id);
+ next;
+ }
+ my $ok;
+ eval{
+ $ok=zebrado($marcxml,$operation,$server);
+ };
+ print "ZEBRAopserver returned : $ok \n" if $verbose;
+ $delsth->execute($id) if ($ok==1);
+}
+
+print "sleeping for $wait seconds now\n" if $verbose;
+sleep $wait;
+goto AGAIN;
+
+sub zebrado {
+
+ ###Accepts a $server variable thus we can use it to update biblios, authorities or other zebra dbs
+ my ($record,$op,$server,$biblionumber)=@_;
+
+ my @port;
+
+ my $tried=0;
+ my $recon=0;
+ my $reconnect=0;
+# $record=Encode::encode("UTF-8",$record);
+ my $shadow=$server."shadow";
+reconnect:
+
+ my $Zconn=C4::Context->Zconn($server, 0, 1);
+ if ($record){
+ print "updating\n" if $verbose;
+ my $Zpackage = $Zconn->package();
+ $Zpackage->option(action => $op);
+ $Zpackage->option(record => $record);
+ $Zpackage->option(recordIdOpaque => $biblionumber);
+retry:
+ $Zpackage->send("update");
+ my($error, $errmsg, $addinfo, $diagset) = $Zconn->error_x();
+ if ($error==10007 && $tried<3) {## timeout --another 30 looonng seconds for this update
+ print "error 10007\n" if $verbose;
+ sleep 1; ## wait a sec!
+ $tried=$tried+1;
+ goto "retry";
+ }elsif ($error==2 && $tried<2) {## timeout --temporary zebra error !whatever that means
+ print "error 2\n" if $verbose;
+ sleep 2; ## wait two seconds!
+ $tried=$tried+1;
+ goto "retry";
+ }elsif($error==10004 && $recon==0){##Lost connection -reconnect
+ print "error 10004\n" if $verbose;
+ sleep 1; ## wait a sec!
+ $recon=1;
+ $Zpackage->destroy();
+ $Zconn->destroy();
+ goto "reconnect";
+ }elsif ($error){
+ # warn "Error-$server $op /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
+ print "error $error\n" if $verbose;
+ $Zpackage->destroy();
+ $Zconn->destroy();
+ return 0;
+ }
+ $Zpackage->send('commit');
+# $Zpackage->destroy();
+# $Zconn->destroy();
+ print "HERE\n" if $verbose;
+ return 1;
+ }
+ return 0;
+}
\ No newline at end of file
More information about the Koha-cvs
mailing list