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

(-)a/misc/background_jobs_worker.pl (-4 / +19 lines)
Lines 51-66 while (1) { Link Here
51
        # FIXME This means we need to have create the DB entry before
51
        # FIXME This means we need to have create the DB entry before
52
        # It could work in a first step, but then we will want to handle job that will be created from the message received
52
        # It could work in a first step, but then we will want to handle job that will be created from the message received
53
        my $job = Koha::BackgroundJobs->find($args->{job_id});
53
        my $job = Koha::BackgroundJobs->find($args->{job_id});
54
        my $success = $job->process( $args );
55
54
56
        $conn->ack( { frame => $frame } ); # FIXME depending on $success?
55
        process_job( $job, $args );
56
        $conn->ack( { frame => $frame } ); # FIXME depending on success?
57
57
    } else {
58
    } else {
58
        my $jobs = Koha::BackgroundJobs->search({ status => 'new' });
59
        my $jobs = Koha::BackgroundJobs->search({ status => 'new' });
59
        while ( my $job = $jobs->next ) {
60
        while ( my $job = $jobs->next ) {
60
            my $args = decode_json($job->data);
61
            my $args = decode_json($job->data);
61
            $job->process( { job_id => $job->id, %$args } );
62
            process_job( $job, { job_id => $job->id, %$args } );
62
        }
63
        }
63
        sleep 10;
64
        sleep 10;
64
    }
65
    }
65
}
66
}
66
$conn->disconnect;
67
$conn->disconnect;
67
- 
68
69
sub process_job {
70
    my ( $job, $args ) = @_;
71
72
    my $pid;
73
    if ( $pid = fork ) {
74
        wait;
75
        return;
76
    }
77
78
    die "fork failed!" unless defined $pid;
79
80
    $job->process( $args );
81
    exit;
82
}

Return to bug 27756