[open-ils-commits] r16442 - trunk/Open-ILS/src/support-scripts (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon May 17 13:08:30 EDT 2010
Author: erickson
Date: 2010-05-17 13:08:26 -0400 (Mon, 17 May 2010)
New Revision: 16442
Modified:
trunk/Open-ILS/src/support-scripts/edi_pusher.pl
Log:
added support for redelivery of 'retry' edi_messages. added support for filting on ORDERS message types
Modified: trunk/Open-ILS/src/support-scripts/edi_pusher.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/edi_pusher.pl 2010-05-17 16:47:32 UTC (rev 16441)
+++ trunk/Open-ILS/src/support-scripts/edi_pusher.pl 2010-05-17 17:08:26 UTC (rev 16442)
@@ -64,7 +64,7 @@
printf "%3s - '%s'\n", $def->id, $def->name;
# give me all completed JEDI events that link to purchase_orders
- # that have not already been delivered to the vendor
+ # that have no delivery attempts or are in the retry state
my $query = {
select => {atev => ['id']},
from => 'atev',
@@ -72,17 +72,12 @@
event_def => $def->id,
state => 'complete',
target => {
- in => {
- select => {acqpo => ['id']},
- from => 'acqpo',
+ 'not in' => {
+ select => {acqedim => ['purchase_order']},
+ from => 'acqedim',
where => {
- id => {
- 'not in' => {
- select => {acqedim => ['purchase_order']},
- from => 'acqedim',
- where => {purchase_order => {'!=' => undef}}
- }
- }
+ message_type => 'ORDERS',
+ status => {'!=' => 'retry'}
}
}
}
@@ -93,6 +88,12 @@
$query->{limit} = $remaining if $remaining > 0;
my $events = $e->json_query($query);
+
+ if(!$events) {
+ $logger->error("error querying JEDI events for event definition $def->id");
+ next;
+ }
+
$remaining -= scalar(@$events);
print "Event definition ", $def->id, " has ", scalar(@$events), " event(s)\n";
@@ -103,10 +104,7 @@
{flesh => 1, flesh_fields => {atev => ['template_output']}}
]);
- my $message = Fieldmapper::acq::edi_message->new;
- $message->create_time('NOW'); # will need this later when we try to update from the object
- print "Event ", $event->id, " targets PO ", $event->target, ":\n"; # target is an opaque identifier, so we cannot flesh it
- print Dumper($event), "\n";
+
my $target = $e->retrieve_acq_purchase_order([ # instead we retrieve it separately
$event->target, {
flesh => 2,
@@ -117,25 +115,52 @@
}
]);
- $message->purchase_order($target->id);
+ # this may be a retry attempt. if so, reuse the original edi_message
+ my $message = $e->search_acq_edi_message({
+ purchase_order => $target->id,
+ message_type => 'ORDERS',
+ status => 'retry'
+ })->[0];
- $debug and print "Target: ", Dumper($target), "\n";
+ if(!$message) {
+ $message = Fieldmapper::acq::edi_message->new;
+ $message->create_time('NOW'); # will need this later when we try to update from the object
+ $message->purchase_order($target->id);
+ $message->message_type('ORDERS');
+ $message->isnew(1);
+ }
+
my $logstr = sprintf "provider %s (%s)", $target->provider->id, $target->provider->name;
unless ($target->provider->edi_default and $message->account($target->provider->edi_default->id)) {
printf STDERR "ERROR: No edi_default account found for $logstr. File will not be sent!\n";
}
+
$message->jedi($event->template_output()->data);
+
print "\ntarget->provider->edi_default->id: ", $target->provider->edi_default->id, "\n";
print "\nNow calling attempt_translation\n\n";
+
unless (OpenILS::Application::Acq::EDI->attempt_translation($message, 1)) {
print STDERR "ERROR: attempt_translation failed, skipping message\n";
next;
# The premise here is that if the translator failed, it is better to try again later from a "fresh" fetched file
# than to add a cascade of failing inscrutable copies of the same message(s) to our DB.
}
+
print "Writing new message + translation to DB\n";
+
$e->xact_begin;
- $e->create_acq_edi_message($message) or warn "create_acq_edi_message failed! $!";
+ if($message->isnew) {
+ unless($e->create_acq_edi_message($message)) {
+ $logger->error("Error creating acq.edi_message for PO ".$target->id.' : '.$e->die_event);
+ next;
+ }
+ } else {
+ unless($e->update_acq_edi_message($message)) {
+ $logger->error("Error updating acq.edi_message for PO ".$target->id.' : '.$e->die_event);
+ next;
+ }
+ }
$e->xact_commit;
print "Calling send_core(...)\n";
More information about the open-ils-commits
mailing list