[open-ils-commits] r14828 - in branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application: . Trigger (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Nov 8 20:09:47 EST 2009
Author: erickson
Date: 2009-11-08 20:09:46 -0500 (Sun, 08 Nov 2009)
New Revision: 14828
Modified:
branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm
branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
Log:
Back-porting:
support for min-passive-delay-age validation
more detailed error logging
fix to max_delay between filter
no longer validate batch passive events during the grouping phase
Modified: branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-11-09 01:07:19 UTC (rev 14827)
+++ branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-11-09 01:09:46 UTC (rev 14828)
@@ -2,7 +2,7 @@
use strict; use warnings;
use OpenSRF::EX qw/:try/;
-use OpenSRF::Utils::Logger qw/:logger/;
+use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Utils::CStoreEditor q/:funcs/;
@@ -113,7 +113,7 @@
$self->cleanedup(1);
}
} otherwise {
- $log->error( shift() );
+ $log->error("Event cleanup failed with ". shift() );
$self->update_state( 'error' ) || die 'Unable to update event state';
};
@@ -148,7 +148,7 @@
->final_result
);
} otherwise {
- $log->error( shift() );
+ $log->error("Event reacting failed with ". shift() );
$self->update_state( 'error' ) || die 'Unable to update event state';
};
@@ -179,7 +179,7 @@
->final_result
);
} otherwise {
- $log->error( shift() );
+ $log->error("Event validation failed with ". shift() );
$self->update_state( 'error' ) || die 'Unable to update event state';
};
Modified: branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm 2009-11-09 01:07:19 UTC (rev 14827)
+++ branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/EventGroup.pm 2009-11-09 01:09:46 UTC (rev 14828)
@@ -4,7 +4,7 @@
use base 'OpenILS::Application::Trigger::Event';
use OpenSRF::EX qw/:try/;
-use OpenSRF::Utils::Logger qw/:level/;
+use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Utils::CStoreEditor q/:funcs/;
@@ -56,7 +56,7 @@
->final_result
);
} otherwise {
- $log->error( shift() );
+ $log->error("Event reacting failed with ". shift() );
$self->update_state( 'error' ) || die 'Unable to update event group state';
};
@@ -90,7 +90,7 @@
$self->{ids} = [ map { $_->id } @valid_events ];
$self->editor->xact_commit;
} otherwise {
- $log->error( shift() );
+ $log->error("Event group validation failed with ". shift() );
$self->editor->xact_rollback;
$self->update_state( 'error' ) || die 'Unable to update event group state';
};
Modified: branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-11-09 01:07:19 UTC (rev 14827)
+++ branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-11-09 01:09:46 UTC (rev 14828)
@@ -14,27 +14,27 @@
my $env = shift;
return 0 if (defined($env->{target}->checkin_time));
- return 0 if ($env->{params}->{max_delay_age} && !$self->MaxPassiveDelayAge($env));
+ if ($env->{params}->{min_target_age}) {
+ $env->{params}->{target_age_field} = 'xact_start';
+ return 0 if (!$self->MinPassiveTargetAge($env));
+ }
+
return 1;
}
-sub MaxPassiveDelayAge {
+sub MinPassiveTargetAge {
my $self = shift;
my $env = shift;
my $target = $env->{target};
- my $delay_field = $env->{event}->event_def->delay_field;
+ my $delay_field = $env->{params}->{target_age_field} || $env->{event}->event_def->delay_field;
my $delay_field_ts = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($target->$delay_field()));
- # the cutoff date is the target timestamp + the delay + the max_delay_age
- # This is also true for negative delays. For example:
- # due_date + "-3 days" + "1 day" == -2 days old.
- $delay_field_ts
- ->add( seconds => interval_to_seconds( $env->{event}->event_def->delay ) )
- ->add( seconds => interval_to_seconds( $env->{params}->{max_delay_age} ) );
+ # to get the minimum time that the target must have aged to, add the min age to the delay field
+ $delay_field_ts->add( seconds => interval_to_seconds( $env->{params}->{min_target_age} ) );
- return 1 if $delay_field_ts > DateTime->now;
+ return 1 if $delay_field_ts <= DateTime->now;
return 0;
}
@@ -45,8 +45,12 @@
return 0 if $circ->checkin_time;
return 0 if $circ->stop_fines and not $circ->stop_fines =~ /MAXFINES|LONGOVERDUE/;
- return 0 if ($env->{params}->{max_delay_age} && !$self->MaxPassiveDelayAge($env));
+ if ($env->{params}->{min_target_age}) {
+ $env->{params}->{target_age_field} = 'xact_start';
+ return 0 if (!$self->MinPassiveTargetAge($env));
+ }
+
my $due_date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($circ->due_date));
return 0 if $due_date > DateTime->now;
Modified: branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
===================================================================
--- branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm 2009-11-09 01:07:19 UTC (rev 14827)
+++ branches/rel_1_6_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm 2009-11-09 01:09:46 UTC (rev 14828)
@@ -391,8 +391,8 @@
my @times = sort {$a <=> $b} interval_to_seconds($def->delay), interval_to_seconds($def->max_delay);
$filter->{ $def->delay_field } = {
'between' => [
- DateTime->now->subtract( seconds => $times[0] )->strftime( '%F %T%z' ),
- DateTime->now->subtract( seconds => $times[1] )->strftime( '%F %T%z' )
+ DateTime->now->subtract( seconds => $times[1] )->strftime( '%F %T%z' ),
+ DateTime->now->subtract( seconds => $times[0] )->strftime( '%F %T%z' )
]
};
} else {
@@ -460,7 +460,6 @@
argc => 2
);
-
sub fire_single_event {
my $self = shift;
my $client = shift;
@@ -469,6 +468,7 @@
my $e = OpenILS::Application::Trigger::Event->new($event_id);
if ($e->validate->valid) {
+ $logger->info("Event is valid, reacting...");
$e->react->cleanup;
}
@@ -496,6 +496,7 @@
my $e = OpenILS::Application::Trigger::EventGroup->new(@$events);
if ($e->validate->valid) {
+ $logger->info("Event group is valid, reacting...");
$e->react->cleanup;
}
@@ -532,7 +533,6 @@
api_level=> 1
);
-
sub grouped_events {
my $self = shift;
my $client = shift;
@@ -542,29 +542,47 @@
my %groups = ( '*' => [] );
for my $e_id ( @$events ) {
- my $e = OpenILS::Application::Trigger::Event->new($e_id);
- if ($e->validate->valid) {
- if (my $group = $e->event->event_def->group_field) {
+ $logger->info("trigger: processing event $e_id");
- # split the grouping link steps
- my @steps = split /\./, $group;
+ # let the client know we're still chugging along TODO add osrf support for method_lookup $client's
+ $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
- # find the grouping object
- my $node = $e->target;
- $node = $node->$_() for ( @steps );
+ my $e;
+ try {
+ $e = OpenILS::Application::Trigger::Event->new($e_id);
+ } catch Error with {
+ $logger->error("Event creation failed with ".shift());
+ };
- # get the pkey value for the grouping object on this event
- my $node_ident = $node->Identity;
- my $ident_value = $node->$node_ident();
+ next unless $e;
- # push this event onto the event+grouping_pkey_value stack
- $groups{$e->event->event_def->id}{$ident_value} ||= [];
- push @{ $groups{$e->event->event_def->id}{$ident_value} }, $e;
- } else {
- # it's a non-grouped event
- push @{ $groups{'*'} }, $e;
- }
+ try {
+ $e->build_environment;
+ } catch Error with {
+ $logger->error("Event environment building failed with ".shift());
+ };
+
+ if (my $group = $e->event->event_def->group_field) {
+
+ # split the grouping link steps
+ my @steps = split /\./, $group;
+
+ # find the grouping object
+ my $node = $e->target;
+ $node = $node->$_() for ( @steps );
+
+ # get the pkey value for the grouping object on this event
+ my $node_ident = $node->Identity;
+ my $ident_value = $node->$node_ident();
+
+ # push this event onto the event+grouping_pkey_value stack
+ $groups{$e->event->event_def->id}{$ident_value} ||= [];
+ push @{ $groups{$e->event->event_def->id}{$ident_value} }, $e;
+ } else {
+ # it's a non-grouped event
+ push @{ $groups{'*'} }, $e;
}
+
$e->editor->disconnect;
}
@@ -582,23 +600,31 @@
my ($groups) = $self->method_lookup('open-ils.trigger.event.find_pending_by_group')->run();
- for my $def ( %$groups ) {
+ for my $def ( keys %$groups ) {
if ($def eq '*') {
for my $event ( @{ $$groups{'*'} } ) {
- $client->respond(
- $self
- ->method_lookup('open-ils.trigger.event.fire')
- ->run($event)
- );
+ try {
+ $client->respond(
+ $self
+ ->method_lookup('open-ils.trigger.event.fire')
+ ->run($event)
+ );
+ } catch Error with {
+ $logger->error("event firing failed with ".shift());
+ };
}
} else {
my $defgroup = $$groups{$def};
for my $ident ( keys %$defgroup ) {
- $client->respond(
- $self
- ->method_lookup('open-ils.trigger.event_group.fire')
- ->run($$defgroup{$ident})
- );
+ try {
+ $client->respond(
+ $self
+ ->method_lookup('open-ils.trigger.event_group.fire')
+ ->run($$defgroup{$ident})
+ );
+ } catch Error with {
+ $logger->error("event firing failed with ".shift());
+ };
}
}
}
More information about the open-ils-commits
mailing list