@ercworldio/blockchain-shared 1.0.20 → 1.0.22
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.
|
@@ -23,9 +23,10 @@ WHERE job_status IN ('pending', 'queued');
|
|
|
23
23
|
markBatchComplete(sweepResults: SweepResult[]): Promise<void>;
|
|
24
24
|
findAndLockQueuedBatchJobs(blockchain: BlockchainType, limit: number | undefined, lock_owner: string, lock_expiry_duration_min?: number, max_retries?: number): Promise<SweepJob[]>;
|
|
25
25
|
findAndLockQueuedJobs(blockchain: BlockchainType, limit: number | undefined, lock_owner: string, lock_expiry_duration_min?: number, max_retries?: number): Promise<SweepJob[]>;
|
|
26
|
-
|
|
26
|
+
request_immediate_sweep(job_ids: number[], max_retries?: number): Promise<number[]>;
|
|
27
27
|
findJobsStateByIds(job_ids: number[]): Promise<Pick<SweepJob, "id" | "blockchain" | "job_status" | "retry_count" | "locked_at" | "lock_expires_at">[]>;
|
|
28
28
|
findAndLockPendingJobs(blockchain: BlockchainType, lock_owner: string, lock_interval_mins?: number, limit?: number, max_retries?: number): Promise<SweepJob[]>;
|
|
29
|
+
findAndLockPendingJobsDue(blockchain: BlockchainType, lock_owner: string, lock_interval_mins?: number, limit?: number, max_retries?: number): Promise<SweepJob[]>;
|
|
29
30
|
createSweepJobDeprec(userId: number, blockchain: string, chainId: string, address: string, parentIndex: number, childIndex: number, token: string, decimals: number, balance: bigint): Promise<SweepJob>;
|
|
30
31
|
dispatchAddSweepJobWithBalanceCheck(wallet_id: number, blockchain: BlockchainType, user_id: number, address: string, parentIndex: number, childIndex: number, is_full_sweep: boolean): Promise<void>;
|
|
31
32
|
batchCreateSweepJob(user_id: number, address: string, parent_index: number, child_index: number, need_sweep: DepositWalletBalance[]): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SweepJobService.d.ts","sourceRoot":"","sources":["../../src/services/SweepJobService.ts"],"names":[],"mappings":"AAAA,OAAO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,CAYhI;IAEK,6BAA6B,GAChC,YAAY,cAAc,EAC1B,OAAO,MAAM,KACd,OAAO,CAAC,QAAQ,EAAE,CAAC,CAsDpB;IAGK,oBAAoB,GACvB,QAAQ,cAAc,EACtB,YAAY,cAAc,EAC1B,OAAO,MAAM,EACb,YAAY,MAAM,KACnB,OAAO,CAAC,QAAQ,EAAE,CAAC,CA4DpB;IAyCK,6BAA6B,GAAU,SAAS,MAAM,EAAE,EAAE,iBAAiB,cAAc,mBAmB/F;IAEM,wBAAwB,GAC3B,aAAa,MAAM,EAAE,EACrB,YAAY,cAAc,EAC1B,gBAAgB,MAAM,EACtB,YAAY,OAAO,KACpB,OAAO,CAAC,IAAI,CAAC,CAcd;IAGK,mCAAmC,GACtC,MAAM,QAAQ,EAAE,EAChB,WAAW,OAAO,KACnB,OAAO,CAAC,IAAI,CAAC,CAsBf;IAEM,uBAAuB,GAAU,MAAM,WAAW,EAAE,EAAE,iBAAiB,cAAc,mBA2B3F;IAEM,iBAAiB,GAAU,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAQjE;IAEI,iCAAiC,CACnC,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAU,GACzB,OAAO,CAAC,QAAQ,EAAE,CAAC;CA2BzB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -518,38 +518,27 @@ WHERE job_status IN ('pending', 'queued');
|
|
|
518
518
|
return rows[0];
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
|
-
//
|
|
522
|
-
//
|
|
523
|
-
|
|
524
|
-
|
|
521
|
+
// On-demand sweep: mark pending or queued jobs due now.
|
|
522
|
+
// Pending jobs are picked up by the urgent funding workers (findAndLockPendingJobsDue); funding
|
|
523
|
+
// keeps sweep_before, so once queued they go to the urgent transfer workers (findAndLockQueuedJobs).
|
|
524
|
+
// No lock is taken here; the workers lock as usual. Returns the ids that were marked.
|
|
525
|
+
request_immediate_sweep(job_ids_1) {
|
|
526
|
+
return __awaiter(this, arguments, void 0, function* (job_ids, max_retries = 5) {
|
|
525
527
|
if (job_ids.length === 0)
|
|
526
528
|
return [];
|
|
527
529
|
const repo = this.getRepo();
|
|
528
530
|
const rows = yield repo.query(`
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
FOR UPDATE SKIP LOCKED
|
|
538
|
-
)
|
|
539
|
-
UPDATE usersmanagement.sweep_jobs j
|
|
540
|
-
SET
|
|
541
|
-
locked_at = now(),
|
|
542
|
-
lock_owner = $2,
|
|
543
|
-
lock_expires_at = now() + ($3 * interval '1 minute'),
|
|
544
|
-
updated_at = now()
|
|
545
|
-
FROM locked
|
|
546
|
-
WHERE j.id = locked.id
|
|
547
|
-
RETURNING j.*;
|
|
548
|
-
`, [job_ids, lock_owner, lock_expiry_duration_min, max_retries]);
|
|
549
|
-
return rows[0];
|
|
531
|
+
UPDATE usersmanagement.sweep_jobs
|
|
532
|
+
SET sweep_before = now(), updated_at = now()
|
|
533
|
+
WHERE id = ANY($1::bigint[])
|
|
534
|
+
AND job_status IN ('pending', 'queued')
|
|
535
|
+
AND retry_count < $2
|
|
536
|
+
RETURNING id;
|
|
537
|
+
`, [job_ids, max_retries]);
|
|
538
|
+
return rows[0].map(r => Number(r.id));
|
|
550
539
|
});
|
|
551
540
|
}
|
|
552
|
-
// Lookup used to explain why requested jobs could not be
|
|
541
|
+
// Lookup used to explain why requested jobs could not be dispatched
|
|
553
542
|
findJobsStateByIds(job_ids) {
|
|
554
543
|
return __awaiter(this, void 0, void 0, function* () {
|
|
555
544
|
if (job_ids.length === 0)
|
|
@@ -576,6 +565,37 @@ WHERE job_status IN ('pending', 'queued');
|
|
|
576
565
|
AND (locked_at IS NULL OR lock_expires_at < now())
|
|
577
566
|
ORDER BY created_at
|
|
578
567
|
LIMIT $2
|
|
568
|
+
FOR UPDATE SKIP LOCKED
|
|
569
|
+
)
|
|
570
|
+
UPDATE usersmanagement.sweep_jobs j
|
|
571
|
+
SET
|
|
572
|
+
locked_at = now(),
|
|
573
|
+
lock_owner = $3,
|
|
574
|
+
lock_expires_at = now() + ($4 * interval '1 minute')
|
|
575
|
+
FROM locked
|
|
576
|
+
WHERE j.id = locked.id
|
|
577
|
+
RETURNING j.*;
|
|
578
|
+
`, [blockchain, limit, lock_owner, lock_interval_mins, max_retries]);
|
|
579
|
+
return rows[0];
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
// Pull pending jobs dispatched on demand (sweep_before set) for the urgent funding workers.
|
|
583
|
+
// Same rules as findAndLockPendingJobs; SKIP LOCKED keeps it from double-locking with the scheduled worker
|
|
584
|
+
findAndLockPendingJobsDue(blockchain_1, lock_owner_1) {
|
|
585
|
+
return __awaiter(this, arguments, void 0, function* (blockchain, lock_owner, lock_interval_mins = 5, limit = 100, max_retries = 5) {
|
|
586
|
+
const repo = this.getRepo();
|
|
587
|
+
const rows = yield repo.query(`
|
|
588
|
+
WITH locked AS (
|
|
589
|
+
SELECT id
|
|
590
|
+
FROM usersmanagement.sweep_jobs
|
|
591
|
+
WHERE job_status = 'pending'
|
|
592
|
+
AND blockchain = $1
|
|
593
|
+
AND sweep_before <= now()
|
|
594
|
+
AND retry_count < $5
|
|
595
|
+
AND (locked_at IS NULL OR lock_expires_at < now())
|
|
596
|
+
ORDER BY sweep_before ASC
|
|
597
|
+
LIMIT $2
|
|
598
|
+
FOR UPDATE SKIP LOCKED
|
|
579
599
|
)
|
|
580
600
|
UPDATE usersmanagement.sweep_jobs j
|
|
581
601
|
SET
|