1 package Koha::BackgroundJob;
4 use JSON qw( encode_json decode_json );
7 use Koha::DateUtils qw( dt_from_string );
8 use Koha::BackgroundJobs;
10 use base qw( Koha::Object );
14 my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect(
15 host => 'localhost', # TODO Move this to KOHA_CONF
26 my ( $self, $params ) = @_;
28 my $job_type = $params->{job_type};
29 my $job_size = $params->{job_size};
30 my $job_args = $params->{job_args};
32 my $json_args = encode_json $job_args;
38 enqueued_on => dt_from_string,
39 borrowernumber => C4::Context->userenv->{id}, # FIXME Handle non GUI calls
42 my $job_id = $self->id;
43 $job_args->{job_id} = $job_id;
44 $json_args = encode_json $job_args,
46 my $conn = $self->connect;
47 my $channel = $conn->open_channel();
49 $channel->declare_queue(
56 routing_key => $job_type, # TODO Must be different?
63 sub process { croak "This method must be subclassed" }
69 my $data_dump = decode_json $self->data;
70 if ( exists $data_dump->{messages} ) {
71 @messages = @{ $data_dump->{messages} };
80 my $data_dump = decode_json $self->data;
81 return $data_dump->{report};
86 return 'BackgroundJob';