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

(-)a/Koha/BackgroundJob.pm (-4 / +2 lines)
Lines 154-168 Process the job! Link Here
154
=cut
154
=cut
155
155
156
sub process {
156
sub process {
157
    my ( $self, $args ) = @_;
157
    my ( $self ) = @_;
158
158
159
    return {} if ref($self) ne 'Koha::BackgroundJob';
159
    return {} if ref($self) ne 'Koha::BackgroundJob';
160
160
161
    my $derived_class = $self->_derived_class;
161
    my $derived_class = $self->_derived_class;
162
162
163
    $args ||= {};
163
    return $derived_class->process({job_id => $self->id});
164
165
    return $derived_class->process({job_id => $self->id, %$args});
166
}
164
}
167
165
168
=head3 job_type
166
=head3 job_type
(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-6 / +7 lines)
Lines 53-71 Process the modification. Link Here
53
=cut
53
=cut
54
54
55
sub process {
55
sub process {
56
    my ( $self, $args ) = @_;
56
    my ( $class, $job_id ) = @_;
57
57
58
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
58
    my $job = Koha::BackgroundJobs->find( $job_id );
59
59
60
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
60
    if ( !$job || $job->status eq 'cancelled' ) {
61
        return;
61
        return;
62
    }
62
    }
63
63
64
    my $job_data = decode_json($job->data);
65
64
    my $job_progress = 0;
66
    my $job_progress = 0;
65
    $job->started_on(dt_from_string)->progress($job_progress)
67
    $job->started_on(dt_from_string)->progress($job_progress)
66
      ->status('started')->store;
68
      ->status('started')->store;
67
69
68
    my @hold_ids = @{ $args->{hold_ids} };
70
    my @hold_ids = @{ $job_data->{hold_ids} };
69
71
70
    my $report = {
72
    my $report = {
71
        total_holds   => scalar @hold_ids,
73
        total_holds   => scalar @hold_ids,
Lines 82-88 sub process { Link Here
82
        my $error = eval {
84
        my $error = eval {
83
            $patron = $hold->patron;
85
            $patron = $hold->patron;
84
            $biblio = $hold->biblio;
86
            $biblio = $hold->biblio;
85
            $hold->cancel( { cancellation_reason => $args->{reason} } );
87
            $hold->cancel( { cancellation_reason => $job_data->{reason} } );
86
        };
88
        };
87
89
88
        if ( $error and $error != $hold or $@ ) {
90
        if ( $error and $error != $hold or $@ ) {
Lines 112-118 sub process { Link Here
112
        $job->progress( ++$job_progress )->store;
114
        $job->progress( ++$job_progress )->store;
113
    }
115
    }
114
116
115
    my $job_data = decode_json $job->data;
116
    $job_data->{messages} = \@messages;
117
    $job_data->{messages} = \@messages;
117
    $job_data->{report}   = $report;
118
    $job_data->{report}   = $report;
118
119
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-8 / +7 lines)
Lines 14-29 sub job_type { Link Here
14
}
14
}
15
15
16
sub process {
16
sub process {
17
    my ( $self, $args ) = @_;
17
    my ( $class, $jobid ) = @_;
18
18
19
    my $job_type = $args->{job_type};
19
    my $job = Koha::BackgroundJobs->find( $job_id );
20
20
21
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
21
    if ( !$job || $job->status eq 'cancelled' ) {
22
23
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
24
        return;
22
        return;
25
    }
23
    }
26
24
25
    my $job_data = decode_json($job->data);
26
27
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
27
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
28
    # Then we will start from scratch and so double delete the same records
28
    # Then we will start from scratch and so double delete the same records
29
29
Lines 33-40 sub process { Link Here
33
        ->status('started')
33
        ->status('started')
34
        ->store;
34
        ->store;
35
35
36
    my $mmtid = $args->{mmtid};
36
    my $mmtid = $job_data->{mmtid};
37
    my @record_ids = @{ $args->{record_ids} };
37
    my @record_ids = @{ $job_data->{record_ids} };
38
38
39
    my $report = {
39
    my $report = {
40
        total_records => scalar @record_ids,
40
        total_records => scalar @record_ids,
Lines 74-80 sub process { Link Here
74
        $job->progress( ++$job_progress )->store;
74
        $job->progress( ++$job_progress )->store;
75
    }
75
    }
76
76
77
    my $job_data = decode_json $job->data;
78
    $job_data->{messages} = \@messages;
77
    $job_data->{messages} = \@messages;
79
    $job_data->{report} = $report;
78
    $job_data->{report} = $report;
80
79
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-8 / +7 lines)
Lines 36-51 Process the job. Link Here
36
=cut
36
=cut
37
37
38
sub process {
38
sub process {
39
    my ( $self, $args ) = @_;
39
    my ( $self, $job_id ) = @_;
40
40
41
    my $job_type = $args->{job_type};
41
    my $job = Koha::BackgroundJobs->find( $job_id );
42
42
43
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
43
    if ( !$job || $job->status eq 'cancelled' ) {
44
45
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
46
        return;
44
        return;
47
    }
45
    }
48
46
47
    my $job_data = decode_json($job->data);
48
49
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
49
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
50
    # Then we will start from scratch and so double delete the same records
50
    # Then we will start from scratch and so double delete the same records
51
51
Lines 55-62 sub process { Link Here
55
        ->status('started')
55
        ->status('started')
56
        ->store;
56
        ->store;
57
57
58
    my $mmtid = $args->{mmtid};
58
    my $mmtid = $job_data->{mmtid};
59
    my @record_ids = @{ $args->{record_ids} };
59
    my @record_ids = @{ $job_data->{record_ids} };
60
60
61
    my $report = {
61
    my $report = {
62
        total_records => scalar @record_ids,
62
        total_records => scalar @record_ids,
Lines 153-159 sub process { Link Here
153
        $job->progress( ++$job_progress )->store;
153
        $job->progress( ++$job_progress )->store;
154
    }
154
    }
155
155
156
    my $job_data = decode_json $job->data;
157
    $job_data->{messages} = \@messages;
156
    $job_data->{messages} = \@messages;
158
    $job_data->{report} = $report;
157
    $job_data->{report} = $report;
159
158
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-8 / +7 lines)
Lines 72-87 The generated report will be: Link Here
72
=cut
72
=cut
73
73
74
sub process {
74
sub process {
75
    my ( $self, $args ) = @_;
75
    my ( $self, $job_id ) = @_;
76
77
    my $job_type = $args->{job_type};
78
76
79
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
77
    my $job = Koha::BackgroundJobs->find( $job_id );
80
78
81
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
79
    if ( !$job || $job->status eq 'cancelled' ) {
82
        return;
80
        return;
83
    }
81
    }
84
82
83
    my $job_data = decode_json($job->data);
84
85
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
85
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
86
    # Then we will start from scratch and so double delete the same records
86
    # Then we will start from scratch and so double delete the same records
87
87
Lines 89-96 sub process { Link Here
89
    $job->started_on(dt_from_string)->progress($job_progress)
89
    $job->started_on(dt_from_string)->progress($job_progress)
90
      ->status('started')->store;
90
      ->status('started')->store;
91
91
92
    my @record_ids     = @{ $args->{record_ids} };
92
    my @record_ids     = @{ $job_data->{record_ids} };
93
    my $delete_biblios = $args->{delete_biblios};
93
    my $delete_biblios = $job_data->{delete_biblios};
94
94
95
    my $report = {
95
    my $report = {
96
        total_records => scalar @record_ids,
96
        total_records => scalar @record_ids,
Lines 182-188 sub process { Link Here
182
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
182
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
183
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
183
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
184
184
185
    my $job_data = decode_json $job->data;
186
    $job_data->{messages} = \@messages;
185
    $job_data->{messages} = \@messages;
187
    $job_data->{report}   = $report;
186
    $job_data->{report}   = $report;
188
187
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-6 / +7 lines)
Lines 53-74 Process the modification. Link Here
53
=cut
53
=cut
54
54
55
sub process {
55
sub process {
56
    my ( $self, $args ) = @_;
56
    my ( $self, $job_id ) = @_;
57
57
58
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
58
    my $job = Koha::BackgroundJobs->find( $job_id );
59
59
60
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
60
    if ( !$job || $job->status eq 'cancelled' ) {
61
        return;
61
        return;
62
    }
62
    }
63
63
64
    my $job_data = decode_json($job->data);
65
64
    my $job_progress = 0;
66
    my $job_progress = 0;
65
    $job->started_on(dt_from_string)
67
    $job->started_on(dt_from_string)
66
        ->progress($job_progress)
68
        ->progress($job_progress)
67
        ->status('started')
69
        ->status('started')
68
        ->store;
70
        ->store;
69
71
70
    my $mmtid = $args->{mmtid};
72
    my $mmtid = $job_data->{mmtid};
71
    my @record_ids = @{ $args->{record_ids} };
73
    my @record_ids = @{ $job_data->{record_ids} };
72
74
73
    my $report = {
75
    my $report = {
74
        total_records => scalar @record_ids,
76
        total_records => scalar @record_ids,
Lines 103-109 sub process { Link Here
103
        $job->progress( ++$job_progress )->store;
105
        $job->progress( ++$job_progress )->store;
104
    }
106
    }
105
107
106
    my $job_data = decode_json $job->data;
107
    $job_data->{messages} = \@messages;
108
    $job_data->{messages} = \@messages;
108
    $job_data->{report} = $report;
109
    $job_data->{report} = $report;
109
110
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-7 / +8 lines)
Lines 55-68 Process the modification. Link Here
55
=cut
55
=cut
56
56
57
sub process {
57
sub process {
58
    my ( $self, $args ) = @_;
58
    my ( $self, $job_id ) = @_;
59
59
60
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
60
    my $job = Koha::BackgroundJobs->find( $job_id );
61
61
62
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
62
    if ( !$job || $job->status eq 'cancelled' ) {
63
        return;
63
        return;
64
    }
64
    }
65
65
66
    my $job_data = decode_json $job->data;
67
66
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
68
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
67
    # Then we will start from scratch and so double process the same records
69
    # Then we will start from scratch and so double process the same records
68
70
Lines 72-79 sub process { Link Here
72
        ->status('started')
74
        ->status('started')
73
        ->store;
75
        ->store;
74
76
75
    my $mmtid = $args->{mmtid};
77
    my $mmtid = $job_data->{mmtid};
76
    my @record_ids = @{ $args->{record_ids} };
78
    my @record_ids = @{ $job_data->{record_ids} };
77
79
78
    my $report = {
80
    my $report = {
79
        total_records => scalar @record_ids,
81
        total_records => scalar @record_ids,
Lines 92-98 sub process { Link Here
92
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
94
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
93
            my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
95
            my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
94
            C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, {
96
            C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, {
95
                overlay_context => $args->{overlay_context},
97
                overlay_context => $job_data->{overlay_context},
96
            });
98
            });
97
        };
99
        };
98
        if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well
100
        if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well
Lines 113-119 sub process { Link Here
113
        $job->progress( ++$job_progress )->store;
115
        $job->progress( ++$job_progress )->store;
114
    }
116
    }
115
117
116
    my $job_data = decode_json $job->data;
117
    $job_data->{messages} = \@messages;
118
    $job_data->{messages} = \@messages;
118
    $job_data->{report} = $report;
119
    $job_data->{report} = $report;
119
120
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-8 / +9 lines)
Lines 83-96 regex_mod allows to modify existing subfield's values using a regular expression Link Here
83
=cut
83
=cut
84
84
85
sub process {
85
sub process {
86
    my ( $self, $args ) = @_;
86
    my ( $self, $job_id ) = @_;
87
87
88
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
88
    my $job = Koha::BackgroundJobs->find( $job_id );
89
89
90
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
90
    if ( !$job || $job->status eq 'cancelled' ) {
91
        return;
91
        return;
92
    }
92
    }
93
93
94
    my $job_data = decode_json encode_utf8 $job->data;
95
94
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
96
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
95
    # Then we will start from scratch and so double process the same records
97
    # Then we will start from scratch and so double process the same records
96
98
Lines 98-108 sub process { Link Here
98
    $job->started_on(dt_from_string)->progress($job_progress)
100
    $job->started_on(dt_from_string)->progress($job_progress)
99
      ->status('started')->store;
101
      ->status('started')->store;
100
102
101
    my @record_ids = @{ $args->{record_ids} };
103
    my @record_ids = @{ $job_id->{record_ids} };
102
    my $regex_mod  = $args->{regex_mod};
104
    my $regex_mod  = $job_id->{regex_mod};
103
    my $new_values = $args->{new_values};
105
    my $new_values = $job_id->{new_values};
104
    my $exclude_from_local_holds_priority =
106
    my $exclude_from_local_holds_priority =
105
      $args->{exclude_from_local_holds_priority};
107
      $job_id->{exclude_from_local_holds_priority};
106
108
107
    my $report = {
109
    my $report = {
108
        total_records            => scalar @record_ids,
110
        total_records            => scalar @record_ids,
Lines 134-140 sub process { Link Here
134
    };
136
    };
135
137
136
    $job->discard_changes;
138
    $job->discard_changes;
137
    my $job_data = decode_json encode_utf8 $job->data;
138
    $job_data->{report} = $report;
139
    $job_data->{report} = $report;
139
140
140
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
141
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
(-)a/misc/background_jobs_worker.pl (-6 / +4 lines)
Lines 60-73 while (1) { Link Here
60
        # It could work in a first step, but then we will want to handle job that will be created from the message received
60
        # It could work in a first step, but then we will want to handle job that will be created from the message received
61
        my $job = Koha::BackgroundJobs->find($args->{job_id});
61
        my $job = Koha::BackgroundJobs->find($args->{job_id});
62
62
63
        process_job( $job, $args );
63
        process_job( $job );
64
        $conn->ack( { frame => $frame } ); # FIXME depending on success?
64
        $conn->ack( { frame => $frame } ); # FIXME depending on success?
65
65
66
    } else {
66
    } else {
67
        my $jobs = Koha::BackgroundJobs->search({ status => 'new' });
67
        my $jobs = Koha::BackgroundJobs->search({ status => 'new' });
68
        while ( my $job = $jobs->next ) {
68
        while ( my $job = $jobs->next ) {
69
            my $args = decode_json($job->data);
69
            process_job( $job );
70
            process_job( $job, { job_id => $job->id, %$args } );
71
        }
70
        }
72
        sleep 10;
71
        sleep 10;
73
    }
72
    }
Lines 75-81 while (1) { Link Here
75
$conn->disconnect;
74
$conn->disconnect;
76
75
77
sub process_job {
76
sub process_job {
78
    my ( $job, $args ) = @_;
77
    my ( $job ) = @_;
79
78
80
    my $pid;
79
    my $pid;
81
    if ( $pid = fork ) {
80
    if ( $pid = fork ) {
Lines 85-90 sub process_job { Link Here
85
84
86
    die "fork failed!" unless defined $pid;
85
    die "fork failed!" unless defined $pid;
87
86
88
    $job->process( $args );
87
    $job->process;
89
    exit;
88
    exit;
90
}
89
}
91
- 

Return to bug 29388