[open-ils-commits] r14693 - in tags/rel_1_6_0_0/Open-ILS: examples src/perlmods/OpenILS/Application/Trigger src/support-scripts (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Oct 29 21:56:01 EDT 2009
Author: erickson
Date: 2009-10-29 21:55:59 -0400 (Thu, 29 Oct 2009)
New Revision: 14693
Added:
tags/rel_1_6_0_0/Open-ILS/examples/action_trigger_filters.json.example
tags/rel_1_6_0_0/Open-ILS/src/support-scripts/action_trigger_runner.pl
Modified:
tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
Log:
backporting max-delay-age validator, action_trigger runner script + trigger filters
Copied: tags/rel_1_6_0_0/Open-ILS/examples/action_trigger_filters.json.example (from rev 14691, branches/rel_1_6/Open-ILS/examples/action_trigger_filters.json.example)
===================================================================
--- tags/rel_1_6_0_0/Open-ILS/examples/action_trigger_filters.json.example (rev 0)
+++ tags/rel_1_6_0_0/Open-ILS/examples/action_trigger_filters.json.example 2009-10-30 01:55:59 UTC (rev 14693)
@@ -0,0 +1,15 @@
+{
+
+'checkout.due' :
+ { 'context_org' : 'circ_lib',
+ 'filter' :
+ { 'checkin_time' : null,
+ '-or' :
+ [ { 'stop_fines' : ['MAXFINES', 'LONGOVERDUE'] },
+ { 'stop_fines' : null }
+ ]
+ }
+ }
+
+}
+
Modified: tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
===================================================================
--- tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm 2009-10-30 01:55:06 UTC (rev 14692)
+++ tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm 2009-10-30 01:55:59 UTC (rev 14693)
@@ -55,19 +55,38 @@
return $U->get_copy_price(new_editor(), $copy_id);
},
+ # given a copy, returns the title and author in a hash
+ get_copy_bib_basics => sub {
+ my $copy_id = shift;
+ my $copy = new_editor()->retrieve_asset_copy([
+ $copy_id,
+ {
+ flesh => 2,
+ flesh_fields => {
+ acp => ['call_number'],
+ acn => ['record']
+ }
+ }
+ ]);
+ if($copy->call_number->id == -1) {
+ return {
+ title => $copy->dummy_title,
+ author => $copy->dummy_author,
+ };
+ } else {
+ my $mvr = $U->record_to_mvr($copy->call_number->record);
+ return {
+ title => $mvr->title,
+ author => $mvr->author
+ };
+ }
+ },
+
# returns the org unit setting value
get_org_setting => sub {
my($org_id, $setting) = @_;
return $U->ou_ancestor_setting_value($org_id, $setting);
},
-
- # returns fines summary information for open transactions
- get_user_fines_summary => sub {
- my $user_id = shift;
- return $U->simplereq(
- 'open-ils.storage',
- 'open-ils.storage.money.open_user_summary.search', $user_id);
- }
};
Modified: tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
===================================================================
--- tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-10-30 01:55:06 UTC (rev 14692)
+++ tags/rel_1_6_0_0/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-10-30 01:55:59 UTC (rev 14693)
@@ -13,9 +13,31 @@
my $self = shift;
my $env = shift;
- return defined($env->{target}->checkin_time) ? 0 : 1;
+ return 0 if (defined($env->{target}->checkin_time));
+ return 0 if ($env->{params}->{max_delay_age} && !$self->MaxPassiveDelayAge($env));
+
+ return 1;
}
+sub MaxPassiveDelayAge {
+ my $self = shift;
+ my $env = shift;
+ my $target = $env->{target};
+ my $delay_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} ) );
+
+ return 1 if $delay_field_ts > DateTime->now;
+ return 0;
+}
+
sub CircIsOverdue {
my $self = shift;
my $env = shift;
@@ -23,6 +45,7 @@
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));
my $due_date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($circ->due_date));
return 0 if $due_date > DateTime->now;
Copied: tags/rel_1_6_0_0/Open-ILS/src/support-scripts/action_trigger_runner.pl (from rev 14691, branches/rel_1_6/Open-ILS/src/support-scripts/action_trigger_runner.pl)
===================================================================
--- tags/rel_1_6_0_0/Open-ILS/src/support-scripts/action_trigger_runner.pl (rev 0)
+++ tags/rel_1_6_0_0/Open-ILS/src/support-scripts/action_trigger_runner.pl 2009-10-30 01:55:59 UTC (rev 14693)
@@ -0,0 +1,161 @@
+#!/usr/bin/perl
+# ---------------------------------------------------------------
+# Copyright (C) 2009 Equinox Software, Inc
+# Author: Bill Erickson <erickson at esilibrary.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# ---------------------------------------------------------------
+use strict;
+use warnings;
+use Getopt::Long;
+use OpenSRF::AppSession;
+use OpenSRF::Utils::JSON;
+use OpenSRF::EX qw(:try);
+require 'oils_header.pl';
+
+my $opt_lockfile = '/tmp/action-trigger-LOCK';
+my $opt_osrf_config = '/openils/conf/opensrf_core.xml';
+my $opt_custom_filter = '/openils/conf/action_trigger_filters.json';
+my $opt_run_pending = 0;
+my $opt_debug_stdout = 0;
+my $opt_help = 0;
+my $opt_hooks;
+
+GetOptions(
+ 'osrf-config=s' => \$opt_osrf_config,
+ 'run-pending' => \$opt_run_pending,
+ 'hooks=s' => \$opt_hooks,
+ 'debug-stdout' => \$opt_debug_stdout,
+ 'custom-filters=s' => \$opt_custom_filter,
+ 'lock-file=s' => \$opt_lockfile,
+ 'help' => \$opt_help,
+);
+
+
+# typical passive hook filters
+my $hook_handlers = {
+
+ # default overdue circulations
+ 'checkout.due' => {
+ context_org => 'circ_lib',
+ filter => {
+ checkin_time => undef,
+ '-or' => [
+ {stop_fines => ['MAXFINES', 'LONGOVERDUE']},
+ {stop_fines => undef}
+ ]
+ }
+ }
+};
+
+if ($opt_custom_filter) {
+ open FILTERS, $opt_custom_filter;
+ $hook_handlers = OpenSRF::Utils::JSON->JSON2Perl(join('',(<FILTERS>)));
+ close FILTERS;
+}
+
+sub help {
+ print <<HELP;
+
+$0 : Create and process action/trigger events
+
+ --osrf-config=<config_file>
+ OpenSRF core config file. Defaults to:
+ /openils/conf/opensrf_core.xml
+
+ --custom-filters=<filter_file>
+ File containing a JSON Object which describes any hooks that should
+ use a user-defined filter to find their target objects. Defaults to:
+ /openils/conf/action_trigger_filters.json
+
+ --run-pending
+ Run pending action_trigger.event's
+
+ --hooks=hook1[,hook2,hook3,...]
+ Hooks for which events should be generated. Defaults to the list of
+ hooks defined in the --custom-filters option.
+
+ --debug-stdout
+ Print server responses to stdout (as JSON) for debugging
+
+ --lock-file=<file_name>
+ Lock file
+
+ --help
+ Show this help
+
+ Examples:
+
+ # To run all pending events. This is what you tell CRON to run at
+ # regular intervals
+ perl $0 --osrf-config /openils/conf/opensrf_core.xml --run-pending
+
+ # To batch create all "checkout.due" events
+ perl $0 --osrf-config /openils/conf/opensrf_core.xml --hooks checkout.due
+
+HELP
+}
+
+
+# create events for the specified hooks using the configured filters and context orgs
+sub process_hooks {
+
+ my @hooks = ($opt_hooks) ? split(',', $opt_hooks) : keys(%$hook_handlers);
+ my $ses = OpenSRF::AppSession->create('open-ils.trigger');
+
+ for my $hook (@hooks) {
+
+ my $config = $$hook_handlers{$hook} or next;
+ my $method = 'open-ils.trigger.passive.event.autocreate.batch';
+ $method =~ s/passive/active/ if $config->{active};
+
+ my $req = $ses->request($method, $hook, $config->{context_org}, $config->{filter});
+ while(my $resp = $req->recv(timeout => 1800)) {
+ if($opt_debug_stdout) {
+ print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
+ }
+ }
+ }
+}
+
+sub run_pending {
+ return unless $opt_run_pending;
+ my $ses = OpenSRF::AppSession->create('open-ils.trigger');
+ my $req = $ses->request('open-ils.trigger.event.run_all_pending');
+ while(my $resp = $req->recv(timeout => 600)) {
+ if($opt_debug_stdout) {
+ print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
+ }
+ }
+}
+
+help() and exit if $opt_help;
+help() and exit unless ($opt_run_pending or $opt_hooks);
+
+# check / set the lockfile
+die "I'm already running with lockfile $opt_lockfile\n" if -e $opt_lockfile;
+open(F, ">$opt_lockfile") or die "Unable to open lockfile $opt_lockfile for writing\n";
+print F $$;
+close F;
+
+try {
+ osrf_connect($opt_osrf_config);
+ process_hooks();
+ run_pending();
+} otherwise {
+ my $e = shift;
+ warn "$e\n";
+};
+
+unlink $opt_lockfile;
+
+
+
More information about the open-ils-commits
mailing list