From 5d50d87127cdaf7639ef5ac74fe9fa453de8e50f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 8 Aug 2012 12:25:27 -0400 Subject: [PATCH] URLVerify.pm; resume options; docs Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/Application/URLVerify.pm | 80 +++++++++++++++++----- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm index 4e65410e21..4df28e5ee4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm @@ -26,8 +26,12 @@ __PACKAGE__->register_method( { desc => q/ Options (optional). - report_all => bypass response throttling and receive all URL sub-process responses. - Not recommened for remote clients, because it can be a lot of data. + report_all => bypass response throttling and return all URL sub-process + responses to the caller. Not recommened for remote (web, etc.) clients, + because it can be a lot of data. + resume_attempt => atttempt_id. Resume verification after a failure. + resume_with_new_attempt => If true, resume from resume_attempt, but + create a new attempt to track the resumption. /, type => 'hash' } @@ -60,10 +64,14 @@ sub validate_session { return $e->die_event unless $e->checkauth; return $e->die_event unless $e->allowed('VERIFY_URL'); - my $session = $e->retrieve_url_verify_session($session_id) or return $e->die_event; + my $session = $e->retrieve_url_verify_session($session_id) + or return $e->die_event; + + my $attempt_id = $options->{resume_attempt}; if (!$url_ids) { - my $ids = $e->json_query({ + + my $query = { select => {uvu => ['id']}, from => { uvu => { # url @@ -71,28 +79,68 @@ sub validate_session { join => { cbreb => { # bucket join => { uvs => { # session filter => {id => $session_id} - }} # noisses - }} # tekcub - } # meti tekcub - } # lru + }} + }} + } + } } - }); + }; + + if ($attempt_id) { + $logger->info("url: resuming attempt $attempt_id"); + + # when resuming an existing attempt (that presumably failed + # mid-processing), we only want to process URLs that either + # have no linked url_verification or have an un-completed + # url_verification. + $query->{from}->{uvu}->{uvuv} = { + type => 'left', + filter => {attempt => $attempt_id} + }; + + $query->{where} = { + '+uvuv' => { + '-or' => [ + {id => undef}, # no verification started + {res_code => undef} # verification started but did no complete + ] + } + }; + } + + my $ids = $e->json_query($query); $url_ids = [ map {$_->{id}} @$ids ]; } my $url_count = scalar(@$url_ids); $logger->info("url: processing $url_count URLs"); - my $attempt = Fieldmapper::url_verify::verification_attempt->new; - $attempt->session($session_id); - $attempt->usr($e->requestor->id); - $attempt->start_time('now'); + my $attempt; + if ($attempt_id and !$options->{resume_with_new_attempt}) { - $e->create_url_verify_verification_attempt($attempt) or return $e->die_event; - $e->commit; + $attempt = $e->retrieve_url_verification_attempt($attempt_id) + or return $e->die_event; + + # no data was written + $e->rollback; + + } else { + + $attempt = Fieldmapper::url_verify::verification_attempt->new; + $attempt->session($session_id); + $attempt->usr($e->requestor->id); + $attempt->start_time('now'); + + $e->create_url_verify_verification_attempt($attempt) + or return $e->die_event; + + $e->commit; + } + + # END DB TRANSACTION - # Now ycle through the URLs in batches. + # Now cycle through the URLs in batches. my $batch_size = 5; # TODO: org setting my $delay = 2; # TODO: org setting -- 2.11.0