From ddc127d8e6fa8c2daf913291f6720768b184dc36 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 6 Dec 2012 16:47:09 -0500 Subject: [PATCH] csv notify fetching script Signed-off-by: Bill Erickson --- Open-ILS/src/support-scripts/csv_notify_fetcher.pl | 85 ++++++++++++++++++++++ Open-ILS/src/support-scripts/csv_notify_pusher.pl | 6 ++ 2 files changed, 91 insertions(+) create mode 100755 Open-ILS/src/support-scripts/csv_notify_fetcher.pl diff --git a/Open-ILS/src/support-scripts/csv_notify_fetcher.pl b/Open-ILS/src/support-scripts/csv_notify_fetcher.pl new file mode 100755 index 0000000000..b033a26a9c --- /dev/null +++ b/Open-ILS/src/support-scripts/csv_notify_fetcher.pl @@ -0,0 +1,85 @@ +#!/usr/bin/perl +use strict; +use warnings; +use DateTime; +use OpenSRF::AppSession; +use OpenILS::Utils::CStoreEditor; +use OpenILS::Utils::Cronscript; +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::Logger qw/$logger/; +binmode(STDOUT, ":utf8"); + +my %defaults = ( + 'osrf-config=s' => '/openils/conf/opensrf_core.xml', + 'response-file=s' => '', + 'verbose' => 0 +); + +sub help { + print <new(\%defaults); +my $opts = $o->MyGetOptions(); +$o->bootstrap; + +my $file = $opts->{'response-file'}; +open(FILE, $file) or + die "Unable to open response file: '$file' : $!\n"; + +my $e = $o->editor(connect => 1); + +while () { + chomp; + + my ($id, $stat) = /"(.+)","(.+)"/g; + next unless $id and $stat; + + $logger->info("csv: processing event $id; stat $stat"); + + my $event = $e->retrieve_action_trigger_event($id); + + if (!$event) { + $logger->warn("csv: unable to find event $id"); + next; + } + + if ($event->async_output) { + $logger->info("csv: skipping event $id; async_output already set"); + next; + } + + $e->xact_begin; + + # store the response output + my $output = Fieldmapper::action_trigger::event_output->new; + $output->data($stat); + + unless ($e->create_action_trigger_event_output($output)) { + $logger->warn("csv: error creating event ". + "output for event $id: ". $e->die_event); + next; + } + + # link the async response output to the original event + $event->async_output($output->id); + + unless ($e->update_action_trigger_event($event)) { + $logger->warn("csv: error updating event $id: ". $e->die_event); + next; + } + + $e->xact_commit; +} + +$e->disconnect; + + diff --git a/Open-ILS/src/support-scripts/csv_notify_pusher.pl b/Open-ILS/src/support-scripts/csv_notify_pusher.pl index 8f147464ea..9cfef0ea3e 100755 --- a/Open-ILS/src/support-scripts/csv_notify_pusher.pl +++ b/Open-ILS/src/support-scripts/csv_notify_pusher.pl @@ -42,6 +42,8 @@ my $end_date = $opts->{'end-date'} || ''; my @event_defs = split(/,/, $opts->{'event-defs'}); +die "--event-defs required\n" unless @event_defs; + if ($verbose) { print "processing event_defs = @event_defs\n"; print "start_date = $start_date\n"; @@ -85,6 +87,10 @@ print "\n"; # dump the CSV chunk from each event output while (my $resp = $req->recv(timeout => 12000)) { + if ($req->failed) { + warn $req->failed; + last; + }; my $content = $resp->content or next; print $content->{data}; } -- 2.11.0