<<

NAME

Koha::BackgroundJob - Koha BackgroundJob Object class

This is a base class for BackgroundJob, some methods must be subclassed.

Example of usage:

Producer: my $job_id = Koha::BackgroundJob->enqueue( { job_type => $job_type, job_size => $job_size, job_args => $job_args } );

Consumer: Koha::BackgroundJobs->find($job_id)->process; See also misc/background_jobs_worker.pl for a full example

API

Class methods

connect

Connect to the message broker using default guest/guest credential

enqueue

Enqueue a new job. It will insert a new row in the DB table and notify the broker that a new job has been enqueued.

job_size is the size of the job job_args is the arguments of the job. It's a structure that will be JSON encoded.

Return the job_id of the newly created job.

process

Process the job!

start

    $self->start;

Marks the job as started.

step

    $self->step;

Makes the job record a step has taken place.

finish

    $self->finish;

Makes the job record as finished. If the job status is cancelled, it is kept.

json

   my $JSON_object = $self->json;

Returns a JSON object with utf8 disabled. Encoding to UTF-8 should be done later.

decoded_data

    my $job_data = $self->decoded_data;

Returns the decoded JSON contents from $self->data.

set_encoded_data

    $self->set_encoded_data( $data );

Serializes $data as a JSON string and sets the data attribute with it.

job_type

Return the job type of the job. Must be a string.

messages

Messages let during the processing of the job.

report

Report of the job.

additional_report

Build additional variables for the job detail view.

cancel

Cancel a job.

Internal methods

_derived_class

type_to_class_mapping

    my $mapping = Koha::BackgroundJob->new->type_to_class_mapping;

Returns the available types to class mappings.

core_types_to_classes

    my $mappings = Koha::BackgroundJob->new->core_types_to_classes

Returns the core background jobs types to class mappings.

plugin_types_to_classes

    my $mappings = Koha::BackgroundJob->new->plugin_types_to_classes

Returns the plugin-defined background jobs types to class mappings.

to_api

    my $json = $job->to_api;

Overloaded method that returns a JSON representation of the Koha::BackgroundJob object, suitable for API output.

to_api_mapping

This method returns the mapping for representing a Koha::BackgroundJob object on the API.

_type

<<