1 package OpenILS::Application::HoldTargeter;
4 use OpenILS::Application;
5 use base qw/OpenILS::Application/;
6 use OpenILS::Utils::HoldTargeter;
7 use OpenSRF::Utils::Logger qw(:logger);
9 __PACKAGE__->register_method(
10 method => 'hold_targeter',
11 api_name => 'open-ils.hold-targeter.target',
15 # Caller is given control over how often to receive responses.
18 desc => q/Batch or single hold targeter./,
25 return_count - Return number of holds processed so far instead
26 of hold targeter result summary objects.
28 return_throttle - Only reply each time this many holds have been
29 targeted. This prevents dumping a fast stream of responses
30 at the client if the client doesn't need them.
34 hold => <id> OR [<id>, <id>, ...]
35 (Re)target one or more specific holds. Specified as a single hold ID
36 or an array ref of hold IDs.
38 retarget_interval => <interval string>
39 Override the 'circ.holds.retarget_interval' global_flag value.
41 soft_retarget_interval => <interval string>
42 Apply soft retarget logic to holds whose prev_check_time sits
43 between the retarget_interval and the soft_retarget_interval.
45 next_check_interval => <interval string>
46 Use this interval to determine when the targeter will run next
47 instead of relying on the retarget_interval. This value is used
48 to determine if an org unit will be closed during the next iteration
49 of the targeter. Applying a specific interval is useful when
50 the retarget_interval is shorter than the time between targeter runs.
53 Target holds in reverse order of create_time.
56 Number of parallel targeters running. This acts as the indication
57 that other targeter instances are running.
59 parallel_slot => n [starts at 1]
60 Sets the parallel targeter instance slot. Used to determine
61 which holds to process to avoid conflicts with other running instances.
65 return => {desc => 'See API Options for return types'}
70 my ($self, $client, $args) = @_;
72 my $targeter = OpenILS::Utils::HoldTargeter->new(%$args);
76 my $throttle = $args->{return_throttle} || 1;
79 my @hold_ids = $targeter->find_holds_to_target;
80 my $total = scalar(@hold_ids);
82 $logger->info("targeter processing $total holds");
84 for my $hold_id (@hold_ids) {
88 OpenILS::Utils::HoldTargeter::Single->new(parent => $targeter);
90 # Don't let an explosion on a single hold stop processing
91 eval { $single->target($hold_id) };
94 my $msg = "Targeter failed processing hold: $hold_id : $@";
97 $single->message($msg) unless $single->message;
100 if (($count % $throttle) == 0) {
101 # Time to reply to the caller. Return either the number
102 # processed thus far or the most recent summary object.
104 my $res = $args->{return_count} ? $count : $single->result;
105 $client->respond($res);
107 $logger->info("targeted $count of $total holds");