diff options
author | Florian Dold <florian@dold.me> | 2023-12-19 00:06:26 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-12-19 00:06:26 +0100 |
commit | c3dbb3a5d578a8e1df6d69f892888e2a9460ddbd (patch) | |
tree | 3f65bb87c411f3c93f5ea6deafa25b771dc53d2b /packages | |
parent | 2db6888c511117a980a04159117c9e9db38e1c05 (diff) | |
download | wallet-core-c3dbb3a5d578a8e1df6d69f892888e2a9460ddbd.tar.xz |
wallet-core: prioritize pending tasks
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 6 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 26 |
2 files changed, 30 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index fe6060499..f4ee80e9e 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -806,7 +806,11 @@ export async function fetchFreshExchange( const nextUpdate = timestampOptionalAbsoluteFromDb( oldExchange.nextUpdateStamp, ); - if (nextUpdate == null || AbsoluteTime.isExpired(nextUpdate)) { + if ( + nextUpdate == null || + AbsoluteTime.isExpired(nextUpdate) || + oldExchange.updateStatus !== ExchangeEntryDbUpdateStatus.Ready + ) { needsUpdate = true; } } diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index e554a9b0f..76b9fd801 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -735,11 +735,27 @@ async function gatherPeerPushCreditPending( ); } +const taskPrio: { [X in PendingTaskType]: number } = { + [PendingTaskType.Deposit]: 2, + [PendingTaskType.ExchangeUpdate]: 1, + [PendingTaskType.PeerPullCredit]: 2, + [PendingTaskType.PeerPullDebit]: 2, + [PendingTaskType.PeerPushCredit]: 2, + [PendingTaskType.Purchase]: 2, + [PendingTaskType.Recoup]: 3, + [PendingTaskType.RewardPickup]: 2, + [PendingTaskType.Refresh]: 3, + [PendingTaskType.Withdraw]: 3, + [PendingTaskType.ExchangeCheckRefresh]: 3, + [PendingTaskType.PeerPushDebit]: 2, + [PendingTaskType.Backup]: 4, +}; + export async function getPendingOperations( ws: InternalWalletState, ): Promise<PendingOperationsResponse> { const now = AbsoluteTime.now(); - return await ws.db + const resp = await ws.db .mktx((x) => [ x.backupProviders, x.exchanges, @@ -776,4 +792,12 @@ export async function getPendingOperations( await gatherPeerPushCreditPending(ws, tx, now, resp); return resp; }); + + resp.pendingOperations.sort((a, b) => { + let prioA = taskPrio[a.type]; + let prioB = taskPrio[b.type]; + return Math.sign(prioA - prioB); + }); + + return resp; } |