locksmanager
v1.4.3
Published
an fully lock api for one-master, one-master-with-multi-cluster.
Downloads
6
Readme
locks manager
an fully lock api for one-master, one-master-with-multi-cluster.
flow (Single process)
lm = new LocksManager();
|
lm.appendLock(ids:string[])
|
(find PER locks by ids. and add ids as CUR locks)
|
(return locksRef)
|
await locksRef.getPreJobsDone()
|
(await Promise.all(PER locks))
|
...do your jobs
|
lm.finishAll()
|
(each CUR locks do unlock. => promise.resolve() )
multi-Progress
there have an default lm
in master process. and child process will share this lm
.
in master process:
import { registerLocksManagerDefaultValueGetter } from 'locksmanager';
// register an value getter function. and also setup.
// or may be just return undefined. it's ok. save the ipc.
registerLocksManagerDefaultValueGetter(async (lock_id)=>{
const model = await db.getById(lock_id);
const {
ignore_pro_A,
ignore_pro_B,
...filtered_fields
} = model;
return filtered_fields;
});
in cluster(worker) process:
import { ClusterLocksManager } from 'locksmanager';
const lm = new ClusterLocksManager();
await lm.appendLock(ids as string[]);
await lm.getPreJobsDone();
// do your jobs
lm.finishAll();