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

(-)a/misc/workers/es_indexer_daemon.pl (-9 / +36 lines)
Lines 65-70 use Koha::SearchEngine::Indexer; Link Here
65
65
66
66
67
my ( $help, $batch_size );
67
my ( $help, $batch_size );
68
69
my $not_found_retries = {};
70
my $max_retries = $ENV{MAX_RETRIES} || 10;
71
68
GetOptions(
72
GetOptions(
69
    'h|help' => \$help,
73
    'h|help' => \$help,
70
    'b|batch_size=s' => \$batch_size
74
    'b|batch_size=s' => \$batch_size
Lines 116-137 while (1) { Link Here
116
            my $body = $frame->body;
120
            my $body = $frame->body;
117
            decode_json($body); # TODO Should this be from_json? Check utf8 flag.
121
            decode_json($body); # TODO Should this be from_json? Check utf8 flag.
118
        } catch {
122
        } catch {
119
            $logger->warn(sprintf "Frame not processed - %s", $_);
123
            Koha::Logger->get({ interface => 'worker' })->warn(sprintf "Frame not processed - %s", $_);
120
            return;
124
            return;
121
        } finally {
122
            $conn->ack( { frame => $frame } );
123
        };
125
        };
124
126
125
        next unless $args;
127
        unless ( $args ) {
128
            Koha::Logger->get({ interface => 'worker' })->warn(sprintf "Frame does not have correct args, ignoring it");
129
            $conn->nack( { frame => $frame, requeue => 'false' } );
130
            next;
131
        }
132
133
        my $job = Koha::BackgroundJobs->find( $args->{job_id} );
126
134
127
        # FIXME This means we need to have create the DB entry before
135
        if ( $job && $job->status ne 'new' ) {
128
        # It could work in a first step, but then we will want to handle job that will be created from the message received
136
            Koha::Logger->get( { interface => 'worker' } )
129
        my $job = Koha::BackgroundJobs->search( { id => $args->{job_id}, status => 'new' } )->next;
137
                ->warn( sprintf "Job %s has wrong status %s", $args->{job_id}, $job->status );
138
139
            # nack without requeue, we do not want to process this frame again
140
            $conn->nack( { frame => $frame, requeue => 'false' } );
141
            next;
142
        }
130
143
131
        unless ($job) {
144
        unless ($job) {
132
            $logger->warn( sprintf "Job %s not found, or has wrong status", $args->{job_id} );
145
            if ( ++$not_found_retries->{$args->{job_id}} >= $max_retries ) {
146
                Koha::Logger->get( { interface => 'worker' } )
147
                    ->warn( sprintf "Job %s not found, no more retry", $args->{job_id} );
148
149
                # nack without requeue, we do not want to process this frame again
150
                $conn->nack( { frame => $frame, requeue => 'false' } );
151
                next;
152
            }
153
154
            Koha::Logger->get( { interface => 'worker' } )
155
                ->debug( sprintf "Job %s not found, will retry later", $args->{job_id} );
156
157
            # nack to force requeue
158
            $conn->nack( { frame => $frame, requeue => 'true' } );
159
            Time::HiRes::sleep(0.5);
133
            next;
160
            next;
134
        }
161
        }
162
        $conn->ack( { frame => $frame } );
135
163
136
        push @jobs, $job;
164
        push @jobs, $job;
137
        if ( @jobs >= $batch_size || !$conn->can_read( { timeout => '0.1' } ) ) {
165
        if ( @jobs >= $batch_size || !$conn->can_read( { timeout => '0.1' } ) ) {
138
- 

Return to bug 35819