Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch from abandoned redlock library to @sesamecare-oss/redlock #723

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/redlock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"watch": "tsc --watch"
},
"dependencies": {
"redlock": "^5.0.0-beta.2"
"@sesamecare-oss/redlock": "^1.3.1"
},
"devDependencies": {
"@nestjs/common": "10.4.4",
Expand Down Expand Up @@ -57,4 +57,4 @@
"default": "./dist/cjs/index.js"
}
}
}
}
2 changes: 1 addition & 1 deletion packages/redlock/src/redlock.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject } from "@nestjs/common";
import { RedlockAbortSignal, Settings } from "redlock";
import { RedlockAbortSignal, Settings } from "@sesamecare-oss/redlock";
import { DEFAULT_DURATION } from "./redlock.constants";
import { RedlockKeyFunction } from "./redlock.interface";
import { RedlockService } from "./redlock.service";
Expand Down
6 changes: 3 additions & 3 deletions packages/redlock/src/redlock.fake-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { EventEmitter } from "events";
import { ExecutionResult, Lock, RedlockAbortSignal, Settings } from "redlock";
import { ExecutionResult, Lock, RedlockAbortSignal, Settings } from "@sesamecare-oss/redlock";

export class FakeRedlockService extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand All @@ -11,7 +11,7 @@ export class FakeRedlockService extends EventEmitter {
}

public async release(lock: Lock, settings?: Partial<Settings> | undefined): Promise<ExecutionResult> {
return { attempts: [] };
return { attempts: [], start: Date.now() };
}

public async extend(existing: Lock, duration: number, settings?: Partial<Settings> | undefined): Promise<Lock> {
Expand Down Expand Up @@ -47,7 +47,7 @@ function createLockFake(): Lock {

// eslint-disable-next-line prefer-const
lock = {
release: async (): Promise<ExecutionResult> => ({ attempts: [] }),
release: async (): Promise<ExecutionResult> => ({ attempts: [], start: Date.now() }),
extend: async (duration: number): Promise<Lock> => lock,
} as Lock;

Expand Down
7 changes: 1 addition & 6 deletions packages/redlock/src/redlock.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Redis, { Cluster } from "ioredis";
import { Settings } from "redlock";
import { Settings } from "@sesamecare-oss/redlock";

export type PreLockedKeysHookArgs = { keys: string[]; duration: number };
export type LockedKeysHookArgs = { keys: string[]; duration: number; elapsedTime: number };
Expand All @@ -15,11 +15,6 @@ export type RedlockModuleOptions = {
decoratorEnabled?: boolean;

settings?: Partial<Settings>;
scripts?: {
readonly acquireScript?: string | ((script: string) => string);
readonly extendScript?: string | ((script: string) => string);
readonly releaseScript?: string | ((script: string) => string);
};
/**
* Hooks called when using @Redlock decorator.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/redlock/src/redlock.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Inject, Injectable } from "@nestjs/common";
import Redlock from "redlock";
import { Redlock } from "@sesamecare-oss/redlock";
import { RedlockModuleOptions } from "./redlock.interface";
import { MODULE_OPTIONS_TOKEN } from "./redlock.module-definition";

@Injectable()
export class RedlockService extends Redlock {
constructor(@Inject(MODULE_OPTIONS_TOKEN) public readonly options: RedlockModuleOptions) {
super(options.clients, options.settings, options.scripts);
super(options.clients, options.settings);
}
}