> [Globals](../globals) / PgIpLock # Class: PgIpLock Implements manageable inter-process locking mechanism over existing PostgreSQL connection for a given `LISTEN` channel. It uses periodic locks acquire retries and implements graceful shutdown using `SIGINT`, `SIGTERM` and `SIGABRT` OS signals, by which safely releases an acquired lock, which causes an event to other similar running instances on another processes (or on another hosts) to capture free lock. By running inside Docker containers this would work flawlessly on implementation auto-scaling services, as docker destroys containers gracefully. Currently, the only known issue could happen only if, for example, database or software (or hardware) in the middle will cause a silent disconnect. For some period of time, despite the fact that there are other live potential listeners some messages can go into void. This time period can be tuned by bypassing wanted `acquireInterval` argument. By the way, take into account that too short period and number of running services may cause huge flood of lock acquire requests to a database, so selecting the proper number should be a thoughtful trade-off between overall system load and reliability level. Usually you do not need instantiate this class directly - it will be done by a PgPubSub instances on their needs. Therefore, you may re-use this piece of code in some other implementations, so it is exported as is. ## Hierarchy * **PgIpLock** ## Implements * [AnyLock](../AnyLock) ## Index ### Constructors * [constructor](PgIpLock#constructor) ### Properties * [channel](PgIpLock#channel) * [options](PgIpLock#options) ### Accessors * [schemaName](PgIpLock#schemaname) ### Methods * [acquire](PgIpLock#acquire) * [destroy](PgIpLock#destroy) * [init](PgIpLock#init) * [isAcquired](PgIpLock#isacquired) * [onRelease](PgIpLock#onrelease) * [release](PgIpLock#release) * [destroy](PgIpLock#destroy) * [hasInstances](PgIpLock#hasinstances) ## Constructors ### constructor \+ **new PgIpLock**(`channel`: string, `options`: [PgIpLockOptions](../PgIpLockOptions)): [PgIpLock](PgIpLock.md) #### Parameters: Name | Type | Description | ------ | ------ | ------ | `channel` | string | source channel name to manage locking on | `options` | [PgIpLockOptions](../PgIpLockOptions) | lock instantiate options | **Returns:** [PgIpLock](PgIpLock) ## Properties ### channel • `Readonly` **channel**: string source channel name to manage locking on ___ ### options • `Readonly` **options**: [PgIpLockOptions](../PgIpLockOptions) lock instantiate options ## Accessors ### schemaName • `Static`get **schemaName**(): string DB lock schema name getter **Returns:** string ## Methods ### acquire ▸ **acquire**(): Promise\ *Implementation of [AnyLock](../AnyLock)* Acquires a lock on the current channel. Returns true on success, false - otherwise **Returns:** Promise\ ___ ### destroy ▸ **destroy**(): Promise\ *Implementation of [AnyLock](../AnyLock)* Destroys this lock properly. **Returns:** Promise\ ___ ### init ▸ **init**(): Promise\ *Implementation of [AnyLock](../AnyLock)* Initializes inter-process locks storage in database and starts listening of lock release events, as well as initializes lock acquire retry timer. **Returns:** Promise\ ___ ### isAcquired ▸ **isAcquired**(): boolean *Implementation of [AnyLock](../AnyLock)* Returns current lock state, true if acquired, false - otherwise. **Returns:** boolean ___ ### onRelease ▸ **onRelease**(`handler`: (channel: string) => void): void This would provide release handler which will be called once the lock is released and the channel name would be bypassed to a given handler #### Parameters: Name | Type | Description | ------ | ------ | ------ | `handler` | (channel: string) => void | | **Returns:** void ___ ### release ▸ **release**(): Promise\ *Implementation of [AnyLock](../AnyLock)* Releases acquired lock on this channel. After lock is released, another running process or host would be able to acquire the lock. **Returns:** Promise\ ___ ### destroy ▸ `Static`**destroy**(): Promise\ Calls destroy() on all created instances at a time **Returns:** Promise\ ___ ### hasInstances ▸ `Static`**hasInstances**(): boolean Returns true if at least one instance was created, false - otherwise **Returns:** boolean