1 package Koha::BackgroundJob;
4 use JSON qw( encode_json decode_json );
9 use Koha::DateUtils qw( dt_from_string );
11 use Koha::BackgroundJob::BatchUpdateBiblio;
12 use Koha::BackgroundJob::BatchUpdateAuthority;
14 use base qw( Koha::Object );
18 my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
19 $stomp->connect( { login => 'guest', passcode => 'guest' } );
24 my ( $self, $params ) = @_;
26 my $job_type = $self->job_type;
27 my $job_size = $params->{job_size};
28 my $job_args = $params->{job_args};
30 my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls
31 my $json_args = encode_json $job_args;
33 $self->_result->result_source->schema->txn_do(
41 enqueued_on => dt_from_string,
42 borrowernumber => $borrowernumber,
47 $job_args->{job_id} = $job_id;
48 $json_args = encode_json $job_args;
50 my $conn = $self->connect;
51 $conn->send_with_receipt( { destination => $job_type, body => $json_args } )
52 or Koha::Exceptions::Exception->throw('Job has not been enqueued');
60 my ( $self, $args ) = @_;
62 my $job_type = $self->type;
63 return $job_type eq 'batch_biblio_record_modification'
64 ? Koha::BackgroundJob::BatchUpdateBiblio->process($args)
65 : $job_type eq 'batch_authority_record_modification'
66 ? Koha::BackgroundJob::BatchUpdateAuthority->process($args)
67 : Koha::Exceptions::Exception->throw('->process called without valid job_type');
70 sub job_type { croak "This method must be subclassed" }
76 my $data_dump = decode_json $self->data;
77 if ( exists $data_dump->{messages} ) {
78 @messages = @{ $data_dump->{messages} };
87 my $data_dump = decode_json $self->data;
88 return $data_dump->{report};
93 $self->status('cancelled')->store;
97 return 'BackgroundJob';