@moneypot/hub 1.20.0-dev.0 → 1.20.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/liability/internal/db.d.ts +1 -4
- package/dist/src/liability/internal/db.js +1 -16
- package/dist/src/liability/internal/index.d.ts +1 -1
- package/dist/src/liability/internal/index.js +1 -1
- package/dist/src/liability/internal/processor.d.ts +4 -0
- package/dist/src/liability/internal/processor.js +2 -3
- package/dist/src/liability/public/config.d.ts +4 -3
- package/dist/src/liability/public/config.js +4 -1
- package/package.json +1 -1
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { PgClientInTransaction } from "../../db/transaction.js";
|
|
2
2
|
import { DbLiability } from "../types.js";
|
|
3
|
-
export declare function
|
|
4
|
-
limit?: number;
|
|
5
|
-
}): Promise<DbLiability[]>;
|
|
6
|
-
export declare function dbGetAndLockLiability(pool: PgClientInTransaction, { id }: {
|
|
3
|
+
export declare function dbLockLiability(pool: PgClientInTransaction, { id }: {
|
|
7
4
|
id: string;
|
|
8
5
|
}): Promise<DbLiability | null>;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
export async function
|
|
2
|
-
const result = await pgClient.query({
|
|
3
|
-
text: `
|
|
4
|
-
SELECT *
|
|
5
|
-
FROM hub.liability
|
|
6
|
-
WHERE resolved_at IS NULL
|
|
7
|
-
AND deadline < now()
|
|
8
|
-
ORDER BY deadline ASC
|
|
9
|
-
LIMIT $1
|
|
10
|
-
FOR UPDATE SKIP LOCKED
|
|
11
|
-
`,
|
|
12
|
-
values: [limit],
|
|
13
|
-
});
|
|
14
|
-
return result.rows;
|
|
15
|
-
}
|
|
16
|
-
export async function dbGetAndLockLiability(pool, { id }) {
|
|
1
|
+
export async function dbLockLiability(pool, { id }) {
|
|
17
2
|
const result = await pool.query({
|
|
18
3
|
text: `
|
|
19
4
|
SELECT *
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { dbLockLiability } from "./db.js";
|
|
2
2
|
export { startLiabilityExpirationProcessor, processExpiredLiabilities, } from "./processor.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { dbLockLiability } from "./db.js";
|
|
2
2
|
export { startLiabilityExpirationProcessor, processExpiredLiabilities, } from "./processor.js";
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as pg from "pg";
|
|
2
2
|
import { LiabilityConfigInternal } from "../public/config.js";
|
|
3
|
+
import { QueryExecutor } from "../../db/util.js";
|
|
4
|
+
export declare function dbGetLiabilityIdsPastDeadline(pgClient: QueryExecutor, { limit }?: {
|
|
5
|
+
limit?: number;
|
|
6
|
+
}): Promise<string[]>;
|
|
3
7
|
export declare function startLiabilityExpirationProcessor<RefType extends string>({ signal, pool, liabilityConfig, }: {
|
|
4
8
|
signal: AbortSignal;
|
|
5
9
|
pool: pg.Pool;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { logger } from "../../logger.js";
|
|
2
2
|
import { withPgPoolTransaction, } from "../../db/transaction.js";
|
|
3
3
|
import { dbLockHouseBankroll, dbLockPlayerBalance } from "../../db/public.js";
|
|
4
|
-
const POLL_INTERVAL = 30_000;
|
|
5
4
|
const BATCH_SIZE = 100;
|
|
6
|
-
async function dbGetLiabilityIdsPastDeadline(pgClient, { limit = 100 } = {}) {
|
|
5
|
+
export async function dbGetLiabilityIdsPastDeadline(pgClient, { limit = 100 } = {}) {
|
|
7
6
|
const result = await pgClient.query({
|
|
8
7
|
text: `
|
|
9
8
|
SELECT id
|
|
@@ -49,7 +48,7 @@ export function startLiabilityExpirationProcessor({ signal, pool, liabilityConfi
|
|
|
49
48
|
logger.error(e, `Error processing expired liabilities`);
|
|
50
49
|
}
|
|
51
50
|
if (!shouldStop && !signal.aborted) {
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, liabilityConfig._options.pollIntervalMs));
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
logger.info(`Liability expiration processor stopped`);
|
|
@@ -21,16 +21,17 @@ export type LiabilityRefTypeConfig<RefType extends string> = {
|
|
|
21
21
|
};
|
|
22
22
|
export declare function createLiabilityConfig<RefType extends string>(refTypes: {
|
|
23
23
|
[K in RefType]: LiabilityRefTypeConfig<K>;
|
|
24
|
-
}, options?: LiabilityConfigOptions): LiabilityConfig<RefType>;
|
|
24
|
+
}, options?: Partial<LiabilityConfigOptions>): LiabilityConfig<RefType>;
|
|
25
25
|
export type LiabilityConfig<RefType extends string> = {
|
|
26
26
|
dbCreateLiability: typeof dbCreateLiability<RefType>;
|
|
27
27
|
dbResolveLiabilityByRef: typeof dbResolveLiabilityByRef<RefType>;
|
|
28
28
|
};
|
|
29
|
-
type LiabilityConfigOptions =
|
|
29
|
+
export type LiabilityConfigOptions = {
|
|
30
|
+
pollIntervalMs: number;
|
|
31
|
+
};
|
|
30
32
|
export type LiabilityConfigInternal<RefType extends string> = LiabilityConfig<RefType> & {
|
|
31
33
|
_refTypes: {
|
|
32
34
|
[K in RefType]: LiabilityRefTypeConfig<K>;
|
|
33
35
|
};
|
|
34
36
|
_options: LiabilityConfigOptions;
|
|
35
37
|
};
|
|
36
|
-
export {};
|
|
@@ -2,10 +2,13 @@ import { dbCreateLiability, dbResolveLiabilityByRef } from "./db.js";
|
|
|
2
2
|
export const LIABILITY_RESOLVED = {
|
|
3
3
|
resolved: true,
|
|
4
4
|
};
|
|
5
|
+
const DEFAULT_OPTIONS = {
|
|
6
|
+
pollIntervalMs: 30_000,
|
|
7
|
+
};
|
|
5
8
|
export function createLiabilityConfig(refTypes, options) {
|
|
6
9
|
return {
|
|
7
10
|
_refTypes: refTypes,
|
|
8
|
-
_options: options,
|
|
11
|
+
_options: { ...DEFAULT_OPTIONS, ...options },
|
|
9
12
|
dbCreateLiability,
|
|
10
13
|
dbResolveLiabilityByRef,
|
|
11
14
|
};
|