Use name suffix instead of complex key object

This commit is contained in:
adrinr 2023-03-07 12:45:20 +01:00
parent 4d854ea5a7
commit 49493d80be
2 changed files with 8 additions and 17 deletions

View File

@ -45,7 +45,8 @@ async function put(
const lockResponse = await locks.doWithLock(
{
type: LockType.TRY_ONCE,
name: LockName.PERSIST_WRITETHROUGH(key!),
name: LockName.PERSIST_WRITETHROUGH,
nameSuffix: key,
ttl: 1000,
},
async () => {

View File

@ -8,22 +8,12 @@ export enum LockType {
DELAY_500 = "delay_500",
}
export class LockName {
static readonly MIGRATIONS = new LockName("migrations")
static readonly TRIGGER_QUOTA = new LockName("trigger_quota")
static readonly SYNC_ACCOUNT_LICENSE = new LockName("sync_account_license")
static readonly UPDATE_TENANTS_DOC = new LockName("update_tenants_doc")
static readonly PERSIST_WRITETHROUGH = (key: string) =>
new LockName(`persist_writethrough_${key}`)
constructor(public readonly value: string) {}
valueOf() {
return this.value
}
toString() {
return this.valueOf()
}
export enum LockName {
MIGRATIONS = "migrations",
TRIGGER_QUOTA = "trigger_quota",
SYNC_ACCOUNT_LICENSE = "sync_account_license",
UPDATE_TENANTS_DOC = "update_tenants_doc",
PERSIST_WRITETHROUGH = "persist_writethrough",
}
export interface LockOptions {