#!/usr/bin/perl # --------------------------------------------------------------- # Copyright (C) 2009 Equinox Software, Inc # Author: Bill Erickson # # 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::System; use OpenSRF::AppSession; use OpenSRF::Utils::JSON; use OpenSRF::Utils::Logger qw/$logger/; use OpenSRF::EX qw(:try); use OpenILS::Utils::Fieldmapper; my $req_timeout = 10800; # DEFAULT values my $opt_lockfile = '/tmp/action-trigger-LOCK'; my $opt_osrf_config = '@sysconfdir@/opensrf_core.xml'; my $opt_custom_filter = '@sysconfdir@/action_trigger_filters.json'; my $opt_max_sleep = 3600; # default to 1 hour my $opt_run_pending = 0; my $opt_debug_stdout = 0; my $opt_help = 0; my $opt_verbose; my $opt_hooks; my $opt_process_hooks = 0; my $opt_granularity = undef; my $opt_gran_only = undef; (-f $opt_custom_filter) or undef($opt_custom_filter); # discard default if no file exists GetOptions( 'max-sleep=i' => \$opt_max_sleep, 'osrf-config=s' => \$opt_osrf_config, 'run-pending' => \$opt_run_pending, 'hooks=s' => \$opt_hooks, 'granularity=s' => \$opt_granularity, 'granularity-only' => \$opt_gran_only, 'process-hooks' => \$opt_process_hooks, 'debug-stdout' => \$opt_debug_stdout, 'custom-filters=s' => \$opt_custom_filter, 'lock-file=s' => \$opt_lockfile, 'verbose' => \$opt_verbose, 'help' => \$opt_help, ); my $max_sleep = $opt_max_sleep; #XXX need to figure out why this is required... $opt_gran_only = $opt_granularity ? 1 : 0; $opt_lockfile .= '.' . $opt_granularity if ($opt_granularity && $opt_gran_only); # typical passive hook filters my $hook_handlers = { # default overdue circulations 'checkout.due' => { context_org => 'circ_lib', filter => { checkin_time => undef, '-or' => [ {stop_fines => ['MAXFINES']}, {stop_fines => undef} ] } } }; if ($opt_custom_filter) { open FILTERS, $opt_custom_filter or die "Cannot read custom filters at $opt_custom_filter"; $hook_handlers = OpenSRF::Utils::JSON->JSON2perl(join('',())); close FILTERS; } sub help { print < OpenSRF core config file. Defaults to: @sysconfdir@/opensrf_core.xml --custom-filters= File containing a JSON Object which describes any hooks that should use a user-defined filter to find their target objects. Defaults to: @sysconfdir@/action_trigger_filters.json --run-pending Run pending events to send emails or take other actions as specified by the reactor in the event definition. --process-hooks Create hook events --max-sleep= When in process-hooks mode, wait up to for the lock file to go away. Defaults to 3600 (1 hour). --hooks=hook1[,hook2,hook3,...] Define which hooks to create events for. If none are defined, it defaults to the list of hooks defined in the --custom-filters option. Requires --process-hooks --granularity=