Lines 90-112
while (1) {
Link Here
|
90 |
next; # will reconnect automatically |
90 |
next; # will reconnect automatically |
91 |
} |
91 |
} |
92 |
|
92 |
|
93 |
my $job; |
93 |
my $args = try { |
94 |
try { |
|
|
95 |
my $body = $frame->body; |
94 |
my $body = $frame->body; |
96 |
my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag. |
95 |
decode_json($body); # TODO Should this be from_json? Check utf8 flag. |
97 |
|
|
|
98 |
# FIXME This means we need to have create the DB entry before |
99 |
# It could work in a first step, but then we will want to handle job that will be created from the message received |
100 |
$job = Koha::BackgroundJobs->find($args->{job_id}); |
101 |
|
102 |
process_job( $job, $args ); |
103 |
} catch { |
96 |
} catch { |
104 |
Koha::Logger->get->warn(sprintf "Job and/or frame not processed - %s", $_); |
97 |
Koha::Logger->get->warn(sprintf "Frame not processed - %s", $_); |
105 |
} finally { |
98 |
} finally { |
106 |
$job->status('failed')->store if $job && @_; |
|
|
107 |
$conn->ack( { frame => $frame } ); |
99 |
$conn->ack( { frame => $frame } ); |
108 |
}; |
100 |
}; |
109 |
|
101 |
|
|
|
102 |
next unless $args; |
103 |
|
104 |
# FIXME This means we need to have create the DB entry before |
105 |
# It could work in a first step, but then we will want to handle job that will be created from the message received |
106 |
my $job = Koha::BackgroundJobs->find($args->{job_id}); |
107 |
|
108 |
unless ( $job ) { |
109 |
Koha::Logger->get->warn(sprintf "No job found for id=%s", $args->{job_id}); |
110 |
next; |
111 |
} |
112 |
|
113 |
process_job( $job, $args ); |
114 |
|
110 |
} else { |
115 |
} else { |
111 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
116 |
my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); |
112 |
while ( my $job = $jobs->next ) { |
117 |
while ( my $job = $jobs->next ) { |
Lines 129-135
sub process_job {
Link Here
|
129 |
|
134 |
|
130 |
die "fork failed!" unless defined $pid; |
135 |
die "fork failed!" unless defined $pid; |
131 |
|
136 |
|
132 |
$job->process( $args ); |
137 |
try { |
|
|
138 |
$job->process( $args ); |
139 |
} catch { |
140 |
$job->status('failed')->store; |
141 |
}; |
133 |
|
142 |
|
134 |
exit; |
143 |
exit; |
135 |
} |
144 |
} |
136 |
- |
|
|