fixing zebraqueue daemon for delete operation part two
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
6a5b9194d5
commit
fcffbe744e
1 changed files with 132 additions and 98 deletions
|
@ -19,7 +19,6 @@ use C4::AuthoritiesMarc;
|
|||
use XML::Simple;
|
||||
use utf8;
|
||||
|
||||
|
||||
my $dbh=C4::Context->dbh;
|
||||
my $ident = "Koha Zebraqueue ";
|
||||
|
||||
|
@ -46,8 +45,9 @@ sub handler_sleep {
|
|||
|
||||
# can be used to slow down loop execution if needed
|
||||
my ( $kernel, $heap, $session ) = @_[ KERNEL, HEAP, SESSION ];
|
||||
|
||||
sleep 1;
|
||||
use Time::HiRes qw (sleep);
|
||||
Time::HiRes::sleep(0.01);
|
||||
#sleep 1;
|
||||
$kernel->yield('status_check');
|
||||
}
|
||||
|
||||
|
@ -77,17 +77,45 @@ sub zebraop {
|
|||
$readsth->execute();
|
||||
Unix::Syslog::syslog LOG_INFO, "Executing zebra operations\n";
|
||||
while (my $data = $readsth->fetchrow_hashref()){
|
||||
warn "Inside while loop" if $debug;
|
||||
eval {
|
||||
my $ok = 0;
|
||||
if ($data->{'operation'} =~ /delete/i ){
|
||||
eval {
|
||||
|
||||
warn "Searching for record to delete" if $debug;
|
||||
# 1st read the record in zebra, we have to get it from zebra as its no longer in the db
|
||||
my $Zconn=C4::Context->Zconn($data->{'server'}, 0, 1,'','xml');
|
||||
my $query = $Zconn->search_pqf( '@attr 1=Local-Number '.$data->{'biblio_auth_number'});
|
||||
my $query = $Zconn->search_pqf( '@attr 1=Local-number '.$data->{'biblio_auth_number'});
|
||||
|
||||
# then, delete the record
|
||||
warn "Deleting record" if $debug;
|
||||
$ok=zebrado($query->record(0)->render(),$data->{'operation'},$data->{'server'},$data->{'biblio_auth_number'});
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
# caught a ZOOM::Exception
|
||||
my $error =
|
||||
$@->message() . " ("
|
||||
. $@->code() . ") "
|
||||
. $@->addinfo() . " "
|
||||
. $@->diagset();
|
||||
warn "ERROR: $error";
|
||||
# this doesn't exist, so no need to wail on zebra to delete it
|
||||
if ($@->code() eq 13) {
|
||||
$ok = 1;
|
||||
}
|
||||
}
|
||||
#if ($ok == 1) {
|
||||
# my $delsth=$dbh->prepare("UPDATE zebraqueue SET done=1 WHERE id =?");
|
||||
# $delsth->execute($data->{'id'});
|
||||
# next;
|
||||
#}
|
||||
|
||||
}
|
||||
else {
|
||||
# it is an update
|
||||
warn "Updating record" if $debug;
|
||||
# get the XML
|
||||
my $marcxml;
|
||||
if ($data->{'server'} eq "biblioserver") {
|
||||
|
@ -139,10 +167,10 @@ sub zebraop {
|
|||
}
|
||||
|
||||
sub zebrado {
|
||||
|
||||
###Accepts a $server variable thus we can use it to update biblios, authorities or other zebra dbs
|
||||
my ($record,$op,$server,$biblionumber)=@_;
|
||||
|
||||
warn "In zebrado" if $debug;
|
||||
my @port;
|
||||
|
||||
my $tried=0;
|
||||
|
@ -150,26 +178,32 @@ sub zebrado {
|
|||
my $reconnect=0;
|
||||
# $record=Encode::encode("UTF-8",$record);
|
||||
my $shadow=$server."shadow";
|
||||
|
||||
$op = 'recordDelete' if $op eq 'delete_record';
|
||||
reconnect:
|
||||
|
||||
my $Zconn=C4::Context->Zconn($server, 0, 1);
|
||||
reconnect:
|
||||
warn "At reconnect" if $debug;
|
||||
my $Zconn=C4::Context->Zconn($server, 0, 1,'','xml');
|
||||
if ($record){
|
||||
warn "Record found" if $debug;
|
||||
my $Zpackage = $Zconn->package();
|
||||
$Zpackage->option(action => $op);
|
||||
$Zpackage->option(record => $record);
|
||||
# $Zpackage->option(recordIdOpaque => $biblionumber) if $biblionumber;
|
||||
retry:
|
||||
$Zpackage->send("update");
|
||||
warn "At Retry" if $debug;
|
||||
eval { $Zpackage->send("update") };
|
||||
if ($@ && $@->isa("ZOOM::Exception")) {
|
||||
print "Oops! ", $@->message(), "\n";
|
||||
return $@->code();
|
||||
}
|
||||
my($error, $errmsg, $addinfo, $diagset) = $Zconn->error_x();
|
||||
if ($error==10007 && $tried<3) {## timeout --another 30 looonng seconds for this update
|
||||
sleep 1; ## wait a sec!
|
||||
$tried=$tried+1;
|
||||
$tried++;
|
||||
goto "retry";
|
||||
}elsif ($error==2 && $tried<2) {## timeout --temporary zebra error !whatever that means
|
||||
sleep 2; ## wait two seconds!
|
||||
$tried=$tried+1;
|
||||
$tried++;
|
||||
goto "retry";
|
||||
}elsif($error==10004 && $recon==0){##Lost connection -reconnect
|
||||
sleep 1; ## wait a sec!
|
||||
|
|
Loading…
Reference in a new issue