The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Redis::JobQueue::Job - Object interface for jobs creating and manipulating

VERSION

This documentation refers to Redis::JobQueue::Job version 0.16

SYNOPSIS

There are several ways to create a Redis::JobQueue::Job object:

    my $pre_job = {
        id           => '4BE19672-C503-11E1-BF34-28791473A258',
        queue        => 'lovely_queue',
        job          => 'strong_job',
        expire       => 12*60*60,               # 12h
        status       => 'created',
        meta_data    => scalar( localtime ),
        workload     => \'Some stuff up to 512MB long',
        result       => \'JOB result comes here, up to 512MB long',
        };

    my $job = Redis::JobQueue::Job->new(
        id           => $pre_job->{id},
        queue        => $pre_job->{queue},
        job          => $pre_job->{job},
        expire       => $pre_job->{expire},
        status       => $pre_job->{status},
        meta_data    => $pre_job->{meta_data},
        workload     => $pre_job->{workload},
        result       => $pre_job->{result},
        );

    $job = Redis::JobQueue::Job->new( $pre_job );

    my $next_job = Redis::JobQueue::Job->new( $job );

Access methods to read and assign the relevant attributes of the object. For example:

    $job->$workload( \'New workload' );
    # or
    $job->$workload( 'New workload' );

    my $id = $job->id;
    # 'workload' and 'result' return a reference to the data
    my $result = ${$job->result};

Returns a list of names of the modified object fields:

    my @modified = $job->modified_attributes;

Resets the sign of changing an attribute. For example:

    $job->clear_variability( qw( status ) );

DESCRIPTION

Job API is implemented by Redis::JobQueue::Job class.

The main features of the Redis::JobQueue::Job class are:

  • Provides an object oriented model of communication.

  • Supports data representing various aspects of the job.

  • Supports the creation of the job object, an automatic allowance for the change attributes and the ability to cleanse the signs of change attributes.

CONSTRUCTOR

An error will cause the program to halt if the argument is not valid.

new( id => $uuid, ... )

It generates a Job object and can be called as either a class method or an object method.

If invoked with the first argument being an object of Redis::JobQueue::Job class or a reference to a hash, then the new object attribute values are taken from the hash of the first argument.

new optionally takes arguments. These arguments are in key-value pairs.

This example illustrates a new() call with all the valid arguments:

    Redis::JobQueue::Job->new(
        id          => '4BE19672-C503-11E1-BF34-28791473A258',
                # UUID string, using conventional UUID string format.
                # Do not use it because filled in automatically when
                # you create a job.
        queue       => 'lovely_queue',  # The name of the job queue.
                                        # (required)
        job         => 'strong_job',    # The name of the job.
                                        # (optional attribute)
        expire      => 12*60*60,        # Job's time to live in seconds.
                                        # 0 for no expire time.
                                        # (required)
        status      => '_created_',     # Current status of the job.
                # Do not use it because value should be set by the worker.
        meta_data   => scalar( localtime ), # Job meta-data, such as custom
                                        # attributes etc. (optional attribute)
        workload    => \'Some stuff up to 512MB long',
                # Baseline data for the function of the worker
                # (the function name specified in the 'job').
                # For example, can be prepared by a function
                # 'Storable::freeze'.
        result      => \'JOB result comes here, up to 512MB long',
                # The result of the function of the worker
                # (the function name specified in the 'job').
                # Do not use it because value should be set by the worker.
        );

Returns the object itself, we can chain settings.

As attributes workload, result may contain a large amount of data, therefore, to improve performance, it is desirable that they be passed as references to the actual data.

Do not use spaces in an id attribute value.

Each element in the struct data has an accessor method, which is used to assign and fetch the element's value.

METHODS

An error will cause the program to halt if the argument is not valid.

id

queue

job

expire

status

meta_data

workload

result

A family of methods for a multitude of accessor methods for your data with the appropriate names. These methods to read and assign the relevant attributes of the object.

As attributes workload, result may contain a large amount of data, for them:

  • A read method returns a reference to the data.

  • A write method can receive both data and a reference to the data.

clear_variability( @fields )

Resets the sign of changing attributes.

modified_attributes

Returns a list of names of the modified object fields.

job_attributes

Returns a list of the names of object attributes.

EXPORT

None by default.

Additional constants are available for import, which can be used to define some type of parameters.

These are the defaults:

Redis::JobQueue::Job::MAX_DATASIZE

Maximum size of the data provided by data on the references workload, result: 512MB.

DIAGNOSTICS

An error will cause the program to halt (confess) if the argument is not valid. Use $@ for the analysis of the specific reasons.

SEE ALSO

The basic operation of the Redis::JobQueue package modules:

Redis::JobQueue - Object interface for creating, executing jobs queues, as well as monitoring the status and results of jobs.

Redis::JobQueue::Job - Object interface for jobs creating and manipulating.

Redis - Perl binding for Redis database.

AUTHOR

Sergey Gladkov, <sgladkov@trackingsoft.com>

CONTRIBUTORS

Alexander Solovey

Jeremy Jordan

Vlad Marchenko

COPYRIGHT AND LICENSE

Copyright (C) 2012-2013 by TrackingSoft LLC. All rights reserved.

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic at http://dev.perl.org/licenses/artistic.html.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.