<<

NAME

Koha::Script - Koha scripts base class

SYNOPSIS

    use Koha::Script
    use Koha::Script -cron;

DESCRIPTION

This class should be used in all scripts. It sets the interface and userenv appropriately.

API

Class methods

new

    my $script = Koha::Script->new(
        {
            script    => $0, # mandatory
          [ lock_name => 'my_script' ]
        }
    );

Create a new Koha::Script object. The script parameter is mandatory, and will usually be passed $0 in the caller script. The lock_name parameter is optional, and is used to generate the lock file if passed.

lock_exec

    # die if cannot get the lock
    try {
        $script->lock_exec;
    }
    catch {
        die "$_";
    };

    # wait for the lock to be released
    $script->lock_exec({ wait => 1 });

This method sets an execution lock to prevent concurrent execution of the caller script. If passed the wait parameter with a true value, it will make the caller wait until it can be granted the lock (flock's LOCK_NB behaviour). It will otherwise throw an exception immediately.

Internal methods

_initialize_locking

    $self->_initialize_locking

This method initializes the locking configuration.

AUTHOR

Martin Renvoize <martin.renvoize@ptfs-europe.com>

<<