View | Details | Raw Unified | Return to bug 27783
Collapse All | Expand All

(-)a/misc/background_jobs_worker.pl (-2 / +52 lines)
Lines 15-26 Link Here
15
# You should have received a copy of the GNU General Public License
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
=head1 NAME
19
20
background_jobs_worker.pl - Worker script that will process background jobs
21
22
=head1 SYNOPSIS
23
24
./background_jobs_worker.pl [--job-type]
25
26
=head1 DESCRIPTION
27
28
This script will connect to the Stomp server (RabbitMQ) and subscribe to the different destination queues available.
29
You can specify some queues only (using --job-type) if you want to run several workers that will handle their own jobs.
30
31
=head1 OPTIONS
32
33
=over
34
35
=item B<--job-type>
36
37
Give the job types this worker will process.
38
39
The different values available are:
40
41
    batch_biblio_record_modification
42
    batch_authority_record_modification
43
    update_elastic_index
44
45
=back
46
47
=cut
48
18
use Modern::Perl;
49
use Modern::Perl;
19
use JSON qw( decode_json );
50
use JSON qw( decode_json );
20
use Try::Tiny qw( catch try );
51
use Try::Tiny qw( catch try );
52
use Pod::Usage;
53
use Getopt::Long;
21
54
22
use Koha::BackgroundJobs;
55
use Koha::BackgroundJobs;
23
56
57
my ( $help, @job_types );
58
GetOptions(
59
    'h|help' => \$help,
60
    'job-type:s' => \@job_types,
61
) || pod2usage(1);
62
63
pod2usage(0) if $help;
64
24
my $conn;
65
my $conn;
25
try {
66
try {
26
    $conn = Koha::BackgroundJob->connect;
67
    $conn = Koha::BackgroundJob->connect;
Lines 28-34 try { Link Here
28
    warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_;
69
    warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_;
29
};
70
};
30
71
31
my @job_types = qw(
72
my @available_job_types = qw(
32
    batch_biblio_record_modification
73
    batch_biblio_record_modification
33
    batch_authority_record_modification
74
    batch_authority_record_modification
34
    batch_item_record_modification
75
    batch_item_record_modification
Lines 36-43 my @job_types = qw( Link Here
36
    batch_authority_record_deletion
77
    batch_authority_record_deletion
37
    batch_item_record_deletion
78
    batch_item_record_deletion
38
    batch_hold_cancel
79
    batch_hold_cancel
80
    update_elastic_index
39
);
81
);
40
82
83
if ( @job_types ) {
84
    for my $job_type ( @job_types ) {
85
        pod2usage( -verbose => 1, -msg => sprintf "You specify an invalid --job-type value: %s\n", $job_type )
86
            unless grep { $_ eq $job_type } @available_job_types;
87
    }
88
} else {
89
    @job_types = @available_job_types;
90
}
91
41
if ( $conn ) {
92
if ( $conn ) {
42
    # FIXME cf note in Koha::BackgroundJob about $namespace
93
    # FIXME cf note in Koha::BackgroundJob about $namespace
43
    my $namespace = C4::Context->config('memcached_namespace');
94
    my $namespace = C4::Context->config('memcached_namespace');
44
- 

Return to bug 27783