]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/HoldTargeter.pm
LP#1541559: org setting for OneClickdigital API base URI
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Application / HoldTargeter.pm
1 package OpenILS::Application::HoldTargeter;
2 use strict; 
3 use warnings;
4 use OpenILS::Application;
5 use base qw/OpenILS::Application/;
6 use OpenILS::Utils::HoldTargeter;
7
8 __PACKAGE__->register_method(
9     method    => 'hold_targeter',
10     api_name  => 'open-ils.hold-targeter.target',
11     api_level => 1,
12     argc      => 1,
13     stream    => 1,
14     # Caller is given control over how often to receive responses.
15     max_chunk_size => 0,
16     signature => {
17         desc     => q/Batch or single hold targeter./,
18         params   => [
19             {   name => 'args',
20                 desc => 'Hash of targeter options',
21                 type => 'hash'
22             }
23         ],
24         return => {
25             desc => q/
26                 TODO
27             /
28         }
29     }
30 );
31
32 # args:
33 #
34 #   return_count - Return number of holds processed so far instead 
35 #       of hold targeter result summary objects.
36 #
37 #   return_throttle - Only reply each time this many holds have been 
38 #       targeted.  This prevents dumping a fast stream of responses
39 #       at the client if the client doesn't need them.
40 #
41 #   See OpenILS::Utils::HoldTargeter::target() docs.
42
43 sub hold_targeter {
44     my ($self, $client, $args) = @_;
45
46     my $targeter = OpenILS::Utils::HoldTargeter->new(%$args);
47
48     $targeter->init;
49
50     my $throttle = $args->{return_throttle} || 1;
51     my $count = 0;
52
53     for my $hold_id ($targeter->find_holds_to_target) {
54         $count++;
55
56         my $single = OpenILS::Utils::HoldTargeter::Single->new(
57             parent => $targeter,
58             skip_viable => $args->{skip_viable}
59         );
60
61         $single->target($hold_id);
62
63         if (($count % $throttle) == 0) { 
64             # Time to reply to the caller.  Return either the number
65             # processed thus far or the most recent summary object.
66
67             my $res = $args->{return_count} ? $count : $single->result;
68             $client->respond($res);
69         }
70     }
71
72     return undef;
73 }
74
75 1;
76