Toggle menu

getLock(lockName[, id, timeout, comment])

Description

Attempts to acquire a named cluster-wide lock.

If a lock with the same name already exists, returns {"lockAcquired": false}. Otherwise, if a lock the lock was created successfully, returns {"lockAcquired": true}.

If the timeout parameter is specified this call will waits 1 + n seconds to acquire the lock, retrying once every second until it succeeds. If not specified no timeout will occur - the getLock call will fail after the first unsuccessful attempt.

Locks are not cleared automatically. They must be released using releaseLocks(lockNames).

If you are working in an End Point, this.getLock should be used. See the End Point "this" object article for more information.

Parameters

NameTypeDescription
lockNameString, requiredThe name of the lock to acquire. This string is unique and acts as the identifier in further lock related requests
timeoutInteger, optionalHow often, in seconds, to attempt to retry obtaining the lock
idInteger, optionalIf specified, stored alongside the lock for debugging purposes
commentString, optionalIf specified, stored alongside the lock for debugging purposes

Example

let lock = this.callWorkerMethod("formutils", "getLock", {
    "lockName": "examplelock",
    "timeout": 1
});

Last modified on 1 August 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon