|
Lines 48-54
The different values available are:
Link Here
|
| 48 |
=cut |
48 |
=cut |
| 49 |
|
49 |
|
| 50 |
use Modern::Perl; |
50 |
use Modern::Perl; |
| 51 |
use JSON qw( decode_json ); |
51 |
use JSON qw( decode_json encode_json ); |
| 52 |
use Try::Tiny qw( catch try ); |
52 |
use Try::Tiny qw( catch try ); |
| 53 |
use Pod::Usage; |
53 |
use Pod::Usage; |
| 54 |
use Getopt::Long; |
54 |
use Getopt::Long; |
|
Lines 73-79
try {
Link Here
|
| 73 |
} catch { |
73 |
} catch { |
| 74 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
74 |
warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; |
| 75 |
}; |
75 |
}; |
| 76 |
|
|
|
| 77 |
if ( $conn ) { |
76 |
if ( $conn ) { |
| 78 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
77 |
# FIXME cf note in Koha::BackgroundJob about $namespace |
| 79 |
my $namespace = C4::Context->config('memcached_namespace'); |
78 |
my $namespace = C4::Context->config('memcached_namespace'); |
|
Lines 96-103
while (1) {
Link Here
|
| 96 |
# It could work in a first step, but then we will want to handle job that will be created from the message received |
95 |
# It could work in a first step, but then we will want to handle job that will be created from the message received |
| 97 |
my $job = Koha::BackgroundJobs->find($args->{job_id}); |
96 |
my $job = Koha::BackgroundJobs->find($args->{job_id}); |
| 98 |
|
97 |
|
| 99 |
process_job( $job, $args ); |
98 |
if ( $job ) { |
| 100 |
$conn->ack( { frame => $frame } ); # FIXME depending on success? |
99 |
process_job( $job, $args ); |
|
|
100 |
$conn->ack( { frame => $frame } ); # FIXME depending on success? |
| 101 |
} else { |
| 102 |
# FIXME if job not found in db, ack this job and requeue as new to retry later |
| 103 |
$conn->ack( { frame => $frame } ); |
| 104 |
$args->{retries} = exists $args->{retries} ? $args->{retries} + 1 : 1; |
| 105 |
if ( $args->{retries} < 100 ) { |
| 106 |
$conn->send( { destination => $frame->destination , body => encode_json($args) } ); |
| 107 |
} else { |
| 108 |
warn "too many attempts, job id: " . $args->{job_id} ; |
| 109 |
} |
| 110 |
} |
| 101 |
|
111 |
|
| 102 |
} else { |
112 |
} else { |
| 103 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
113 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
| 104 |
- |
|
|