Kernel::System::GenericLock

NAME

Kernel::System::GenericLock – generic lock lib

DESCRIPTION

All generic lock functions.

The generic lock API is designed to manage locks on resources in a system. It provides functionality to lock individual resources, unlock all resources, and handle expired locks. Additionally, it allows for retrieving the current state of a lock for a specific resource.

PUBLIC INTERFACE

new()

Don't use the constructor directly, use the ObjectManager instead:

    my $GenericLockObject = $Kernel::OM->Get('Kernel::System::GenericLock');

Lock()

Lock something

    my $Lock = $GenericLockObject->Lock(
        ID     => 'someID', # ID of what should be locked.
        TTL    => $TTL,     # Seconds for max lock duration.
        UserID => 123,      # User is locking the object.
    );
    return if !$Lock;       # Error while locking

    # Locking was successful
    # Go ahead with the rest of the logic.

Return Values:

    1     - Successful lock.
    0     - No lock due to duplicate ID.
    undef - No lock due to some other error.

LockGet()

Get the contents of a lock when present.

    my $Lock = $LockObject->LockGet(
        ID  => $ID,
    );

Returns:

    $Lock = {
        ID       => $ID,
        Expires  => $ExpiresEpochSeconds,
        CreateBy => 123,
        Silent   => 1,                      # 1 or 0, default 0, if active it suppress log errors if not found
    };

UnlockExpired()

Unlock all expired locks.

    $GenericLockObject->UnlockExpired();

Unlock()

Unlock the currently locked task/object.

    my $Success = $LockObject->Unlock(
        ID     => 'someID',
        UserID => 123,
    );
Scroll to Top