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

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

Return to bug 32393