Options
All
  • Public
  • Public/Protected
  • All
Menu

Module distributed

The distributed namespace uses Redis to distribute commands to every node

Index

Functions

acquireLock

  • acquireLock(resource: string, duration: number): Promise<RedisLock | undefined>
  • When a single node must process data from a shared source, call this method to obtain an exclusive lock. You can then call lock.extend() to keep it longer, or lock.unlock() to release it

    Parameters

    • resource: string

      Name of the resource to lock

    • duration: number

      the initial duration

    Returns Promise<RedisLock | undefined>

    undefined if another node already has obtained the lock

broadcast

  • broadcast<T>(fn: Function): Promise<Function>
  • This method returns a function that can then be called to broadcast the message to every node

    example

    const distributeToAll: Function = await bp.distributed.broadcast(_localMethod)

    example

    const _localMethod = (param1, param2): Promise { }

    example

    distributeToAll('send to all nodes', 'other info') // Every node will execute this method

    Type parameters

    • T

      The return type of the returned function

    Parameters

    • fn: Function

      The job that will be executed on all nodes

    Returns Promise<Function>

clearLock

  • clearLock(resource: string): Promise<boolean>
  • Forcefully clears any trace of the lock from the redis store. It doesn't clear the lock from the node which had it. Ensure that a broadcasted job took care of cancelling it before.

    Parameters

    • resource: string

    Returns Promise<boolean>

    true if an existing lock was deleted

Generated using TypeDoc