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

(-)a/misc/background_jobs_worker.pl (-11 / +18 lines)
Lines 49-58 The different values available are: Link Here
49
49
50
use Modern::Perl;
50
use Modern::Perl;
51
use JSON qw( decode_json );
51
use JSON qw( decode_json );
52
use Try::Tiny qw( catch try );
52
use Try::Tiny;
53
use Pod::Usage;
53
use Pod::Usage;
54
use Getopt::Long;
54
use Getopt::Long;
55
55
56
use Koha::Logger;
56
use Koha::BackgroundJobs;
57
use Koha::BackgroundJobs;
57
58
58
my ( $help, @queues );
59
my ( $help, @queues );
Lines 89-103 while (1) { Link Here
89
            next;    # will reconnect automatically
90
            next;    # will reconnect automatically
90
        }
91
        }
91
92
92
        my $body = $frame->body;
93
        my $job;
93
        my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag.
94
        try {
94
95
            my $body = $frame->body;
95
        # FIXME This means we need to have create the DB entry before
96
            my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag.
96
        # It could work in a first step, but then we will want to handle job that will be created from the message received
97
97
        my $job = Koha::BackgroundJobs->find($args->{job_id});
98
            # FIXME This means we need to have create the DB entry before
98
99
            # It could work in a first step, but then we will want to handle job that will be created from the message received
99
        process_job( $job, $args );
100
            $job = Koha::BackgroundJobs->find($args->{job_id});
100
        $conn->ack( { frame => $frame } ); # FIXME depending on success?
101
102
            process_job( $job, $args );
103
        } catch {
104
            Koha::Logger->get->warn(sprintf "Job and/or frame not processed - %s", $_);
105
        } finally {
106
            $job->status('failed')->store if $job;
107
            $conn->ack( { frame => $frame } );
108
        };
101
109
102
    } else {
110
    } else {
103
        my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
111
        my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
104
- 

Return to bug 32393