interface Lease {
    client: K8;
    durationSeconds: number;
    leaseHolder: LeaseHolder;
    leaseName: string;
    namespace: string;
    renewalService: LeaseRenewalService;
    scheduleId: number;
    acquire(): Promise<void>;
    isAcquired(): Promise<boolean>;
    isExpired(): Promise<boolean>;
    release(): Promise<void>;
    renew(): Promise<void>;
    tryAcquire(): Promise<boolean>;
    tryRelease(): Promise<boolean>;
    tryRenew(): Promise<boolean>;
}

Implemented by

Properties

client: K8
durationSeconds: number
leaseHolder: LeaseHolder
leaseName: string
namespace: string
renewalService: LeaseRenewalService
scheduleId: number

Methods

  • Acquires the lease. If the lease is already acquired, it checks if the lease is expired or held by the same process. If the lease is expired, it creates a new lease. If the lease is held by the same process, it renews the lease. If the lease is held by another process, then an exception is thrown.

    Returns Promise<void>

    LeaseAcquisitionError - If the lease is already acquired by another process or an error occurs during acquisition.

  • Checks if the lease is acquired. If the lease is acquired and not expired, it returns true; otherwise, false.

    Returns Promise<boolean>

    true if the lease is acquired and not expired; otherwise, false.

  • Checks if the lease is expired. If the lease is expired, it returns true; otherwise, false. This method does not verify if the lease is acquired by the current process.

    Returns Promise<boolean>

    true if the lease is expired; otherwise, false.

  • Releases the lease. If the lease is expired or held by the same process, it deletes the lease. If the lease is held by another process, then an exception is thrown.

    Returns Promise<void>

    LeaseRelinquishmentError - If the lease is already acquired by another process or an error occurs during relinquishment.

  • Renews the lease. If the lease is expired or held by the same process, it creates or renews the lease. If the lease is held by another process, then an exception is thrown.

    Returns Promise<void>

    LeaseAcquisitionError - If the lease is already acquired by another process or an error occurs during renewal.

  • Attempts to acquire the lease, by calling the acquire method. If an exception is thrown, it is caught and false is returned. If the lease is successfully acquired, true is returned; otherwise, false is returned.

    Returns Promise<boolean>

    true if the lease is successfully acquired; otherwise, false.

  • Attempts to release the lease, by calling the release method. If an exception is thrown, it is caught and false is returned. If the lease is successfully released, true is returned; otherwise, false is returned.

    Returns Promise<boolean>

    true if the lease is successfully released; otherwise, false.

  • Attempts to renew the lease, by calling the renew method. If an exception is thrown, it is caught and false is returned. If the lease is successfully renewed, true is returned; otherwise, false is returned.

    Returns Promise<boolean>

    true if the lease is successfully renewed; otherwise, false.