Skip to content

basalt / scheduler/src / ScheduleLock

Interface: ScheduleLock ​

Defined in: scheduler/src/index.ts:63

Cross-replica mutex for .onOneServer() entries. acquire must be ATOMIC across processes (e.g. Redis SET key value PX ttl NX): it returns true for exactly one caller per key until the TTL expires. There is deliberately no release — the key covers the tick window, so a fast first run cannot be followed by a late replica re-acquiring and running the same minute again.

ioredis example:

const lock: ScheduleLock = {
  async acquire(key, ttlMs) {
    return (await redis.set(key, '1', 'PX', ttlMs, 'NX')) === 'OK'
  },
}

Methods ​

acquire() ​

> acquire(key, ttlMs): Promise<boolean>

Defined in: scheduler/src/index.ts:64

Parameters ​

key ​

string

ttlMs ​

number

Returns ​

Promise<boolean>

Released under the MIT License.