From 21ce6575d3be348da7b895a60b5bf75610739b89 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 7 Sep 2006 02:00:52 +0000 Subject: [PATCH] making more robust, re-connects after jabber failures, checks for high counts on noncat and in_house git-svn-id: svn://svn.open-ils.org/ILS/trunk@6012 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/offline/offline.pl | 57 +++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/offline/offline.pl b/Open-ILS/src/offline/offline.pl index 0ab1751503..f7262b69d1 100755 --- a/Open-ILS/src/offline/offline.pl +++ b/Open-ILS/src/offline/offline.pl @@ -54,12 +54,15 @@ my $evt; # this is moved to mod_perl # -------------------------------------------------------------------- sub ol_init { - #_ol_debug_params(); - #$DB->DBFile($config{db}); $DB->DBFile($config{dsn}, $config{usr}, $config{pw}); + ol_connect(); +} + +sub ol_connect { OpenSRF::System->bootstrap_client(config_file => $bootstrap ); Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); + } @@ -518,20 +521,37 @@ sub ol_process_commands { my $t = $d->{type}; my $last = ($x++ == scalar(@$commands) - 1) ? 1 : 0; my $res = { command => $d }; + my $err; - try { - $res->{event} = ol_handle_checkin($d) if $t eq 'checkin'; - $res->{event} = ol_handle_inhouse($d) if $t eq 'in_house_use'; - $res->{event} = ol_handle_checkout($d) if $t eq 'checkout'; - $res->{event} = ol_handle_renew($d) if $t eq 'renew'; - $res->{event} = ol_handle_register($d) if $t eq 'register'; + while( 1 ) { - } catch Error with { - my $e = shift; - $res->{event} = OpenILS::Event->new( - 'INTERNAL_SERVER_ERROR', debug => "$e"); - }; + $err = undef; + $logger->debug("offline: top of execute loop : $t"); + + try { + $res->{event} = ol_handle_checkin($d) if $t eq 'checkin'; + $res->{event} = ol_handle_inhouse($d) if $t eq 'in_house_use'; + $res->{event} = ol_handle_checkout($d) if $t eq 'checkout'; + $res->{event} = ol_handle_renew($d) if $t eq 'renew'; + $res->{event} = ol_handle_register($d) if $t eq 'register'; + + } catch Error with { $err = shift; }; + + if( $err ) { + if( ref($err) eq 'OpenSRF::EX::JabberDisconnected' ) { + $logger->error("offline: we lost jabber .. trying to reconnect"); + ol_connect(); + + } else { + $res->{event} = OpenILS::Event->new('INTERNAL_SERVER_ERROR', debug => "$err"); + last; + } + + } else { last; } + + sleep(1); + } ol_append_result($res, $last); $session->num_complete( $session->num_complete + 1 ); @@ -559,6 +579,11 @@ sub ol_handle_inhouse { $logger->activity("offline: in_house_use : requestor=". $requestor->id.", realtime=$realtime, ". "workstation=$ws, barcode=$barcode, count=$count, use_time=$use_time"); + if( $count > 99 ) { + return OpenILS::Event->new( + 'INTERNAL_SERVER_ERROR', payload => 'TOO MANY IN HOUSE USE'); + } + my $ids = $U->simplereq( 'open-ils.circ', 'open-ils.circ.in_house_use.create', $authtoken, @@ -614,6 +639,12 @@ sub ol_circ_args_from_command { sub ol_handle_checkout { my $command = shift; my $args = ol_circ_args_from_command($command); + + if( $args->{noncat} and $args->{noncat_count} > 99 ) { + return OpenILS::Event->new( + 'INTERNAL_SERVER_ERROR', payload => 'TOO MANY NON CATS'); + } + return $U->simplereq( 'open-ils.circ', 'open-ils.circ.checkout', $authtoken, $args ); } -- 2.43.2