1 package Koha::BackgroundJob;
4 use JSON qw( encode_json decode_json );
9 use Koha::DateUtils qw( dt_from_string );
10 use Koha::BackgroundJobs;
12 use base qw( Koha::Object );
16 my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
17 host => 'localhost', # TODO Move this to KOHA_CONF
28 my ( $self, $params ) = @_;
30 my $job_type = $params->{job_type};
31 my $job_size = $params->{job_size};
32 my $job_args = $params->{job_args};
34 my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls
35 my $json_args = encode_json $job_args;
41 enqueued_on => dt_from_string,
42 borrowernumber => $borrowernumber,
45 my $job_id = $self->id;
46 $job_args->{job_id} = $job_id;
47 $json_args = encode_json $job_args,
49 my $conn = $self->connect;
50 my $channel = $conn->open_channel();
52 $channel->declare_queue(
59 routing_key => $job_type, # TODO Must be different?
66 sub process { croak "This method must be subclassed" }
72 my $data_dump = decode_json $self->data;
73 if ( exists $data_dump->{messages} ) {
74 @messages = @{ $data_dump->{messages} };
83 my $data_dump = decode_json $self->data;
84 return $data_dump->{report};
89 $self->status('cancelled')->store;
93 return 'BackgroundJob';