Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Dec 6, 2024
2 parents d249fe1 + a286aba commit a20c05a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Common/Server/Infrastructure/Semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Redis, { ClientType } from "./Redis";
import { Mutex } from "redis-semaphore";
import { Mutex, LockOptions } from "redis-semaphore";

export type SemaphoreMutex = Mutex;

Expand All @@ -8,7 +8,8 @@ export default class Semaphore {
public static async lock(data: {
key: string;
namespace: string;
lockTimeout?: number;
lockTimeout?: number | undefined;
acquireTimeout?: number | undefined;
}): Promise<SemaphoreMutex> {
if (!data.lockTimeout) {
data.lockTimeout = 5000;
Expand All @@ -22,12 +23,20 @@ export default class Semaphore {
throw new Error("Redis client is not connected");
}

const lockOptions: LockOptions = {};

if (data.lockTimeout) {
lockOptions.lockTimeout = data.lockTimeout;
}

if (data.acquireTimeout) {
lockOptions.acquireTimeout = data.acquireTimeout;
}

const mutex: SemaphoreMutex = new Mutex(
client,
data.namespace + "-" + key,
{
lockTimeout: data.lockTimeout,
},
lockOptions,
);

await mutex.acquire();
Expand Down
2 changes: 2 additions & 0 deletions ProbeIngest/API/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ router.post(
mutex = await Semaphore.lock({
key: probeId.toString(),
namespace: "MonitorAPI.monitor-list",
lockTimeout: 15000,
acquireTimeout: 20000,
});
} catch (err) {
logger.error(err);
Expand Down

0 comments on commit a20c05a

Please sign in to comment.