diff options
author | Sebastian <sebasjm@gmail.com> | 2024-02-28 22:41:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-02-28 22:41:41 -0300 |
commit | 74b9ee559fc57f48a591140eb342cc8e2bbd3dd3 (patch) | |
tree | c26fb1cf465edc41ba625ce790eed2c71f308f77 /packages/taler-wallet-core/src | |
parent | 83c5a50f6c95a9ddde0db6ae1eeb6039550375e5 (diff) | |
download | wallet-core-74b9ee559fc57f48a591140eb342cc8e2bbd3dd3.tar.gz wallet-core-74b9ee559fc57f48a591140eb342cc8e2bbd3dd3.tar.bz2 wallet-core-74b9ee559fc57f48a591140eb342cc8e2bbd3dd3.zip |
get activity
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/observable-wrappers.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/shepherd.ts | 7 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet-api-types.ts | 11 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 41 |
4 files changed, 58 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/observable-wrappers.ts b/packages/taler-wallet-core/src/observable-wrappers.ts index f2c76ae5b..5653f185e 100644 --- a/packages/taler-wallet-core/src/observable-wrappers.ts +++ b/packages/taler-wallet-core/src/observable-wrappers.ts @@ -67,6 +67,10 @@ export class ObservableTaskScheduler implements TaskScheduler { } } + getActiveTasks(): TaskIdStr[] { + return this.impl.getActiveTasks(); + } + ensureRunning(): void { return this.impl.ensureRunning(); } diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts index 8fdf2b66b..6f2b2fa44 100644 --- a/packages/taler-wallet-core/src/shepherd.ts +++ b/packages/taler-wallet-core/src/shepherd.ts @@ -148,6 +148,7 @@ export interface TaskScheduler { stopShepherdTask(taskId: TaskIdStr): void; resetTaskRetries(taskId: TaskIdStr): Promise<void>; reload(): void; + getActiveTasks(): TaskIdStr[]; } export class TaskSchedulerImpl implements TaskScheduler { @@ -171,6 +172,10 @@ export class TaskSchedulerImpl implements TaskScheduler { } } + getActiveTasks(): TaskIdStr[] { + return [...this.sheps.keys()] + } + ensureRunning(): void { if (this.isRunning) { return; @@ -932,7 +937,7 @@ export function listTaskForTransactionId(transactionId: string): TaskIdStr[] { * Convert the task ID for a task that processes a transaction int * the ID for the transaction. */ -function convertTaskToTransactionId( +export function convertTaskToTransactionId( taskId: string, ): TransactionIdStr | undefined { const parsedTaskId = parseTaskIdentifier(taskId); diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 5e2d83a33..e5ff6cc26 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -60,6 +60,7 @@ import { FailTransactionRequest, ForceRefreshRequest, ForgetKnownBankAccountsRequest, + GetActiveTasks, GetAmountRequest, GetBalanceDetailRequest, GetContractTermsDetailsRequest, @@ -186,6 +187,7 @@ export enum WalletApiOperation { GetUserAttentionUnreadCount = "getUserAttentionUnreadCount", MarkAttentionRequestAsRead = "markAttentionRequestAsRead", GetPendingOperations = "getPendingOperations", + GetActiveTasks = "getActiveTasks", SetExchangeTosAccepted = "setExchangeTosAccepted", SetExchangeTosForgotten = "SetExchangeTosForgotten", StartRefundQueryForUri = "startRefundQueryForUri", @@ -1098,6 +1100,14 @@ export type GetPendingTasksOp = { response: any; }; + +export type GetActiveTasksOp = { + op: WalletApiOperation.GetActiveTasks; + request: EmptyObject; + response: GetActiveTasks; +}; + + /** * Dump all coins of the wallet in a simple JSON format. */ @@ -1199,6 +1209,7 @@ export type WalletOperations = { [WalletApiOperation.GetWithdrawalTransactionByUri]: GetWithdrawalTransactionByUriOp; [WalletApiOperation.RetryPendingNow]: RetryPendingNowOp; [WalletApiOperation.GetPendingOperations]: GetPendingTasksOp; + [WalletApiOperation.GetActiveTasks]: GetActiveTasksOp; [WalletApiOperation.GetUserAttentionRequests]: GetUserAttentionRequests; [WalletApiOperation.GetUserAttentionUnreadCount]: GetUserAttentionsUnreadCount; [WalletApiOperation.MarkAttentionRequestAsRead]: MarkAttentionRequestAsRead; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 14f4c85c3..2757f7fec 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -24,6 +24,7 @@ */ import { IDBFactory } from "@gnu-taler/idb-bridge"; import { + ActiveTask, AmountString, Amounts, AsyncCondition, @@ -168,6 +169,7 @@ import { CoinSourceType, ConfigRecordKey, DenominationRecord, + OperationRetryRecord, WalletDbReadOnlyTransaction, WalletStoresV1, clearDatabase, @@ -175,6 +177,8 @@ import { importDb, openStoredBackupsDatabase, openTalerDatabase, + timestampAbsoluteFromDb, + timestampPreciseFromDb, timestampProtocolToDb, } from "./db.js"; import { @@ -238,6 +242,7 @@ import { forceRefresh } from "./refresh.js"; import { TaskScheduler, TaskSchedulerImpl, + convertTaskToTransactionId, listTaskForTransactionId, } from "./shepherd.js"; import { @@ -513,9 +518,9 @@ async function dumpCoins(wex: WalletExecutionContext): Promise<CoinDumpJson> { ageCommitmentProof: c.ageCommitmentProof, spend_allocation: c.spendAllocation ? { - amount: c.spendAllocation.amount, - id: c.spendAllocation.id, - } + amount: c.spendAllocation.amount, + id: c.spendAllocation.id, + } : undefined, }); } @@ -968,6 +973,34 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( await suspendTransaction(wex, req.transactionId); return {}; } + case WalletApiOperation.GetActiveTasks: { + const allTasksId = wex.taskScheduler.getActiveTasks() + + const tasksInfo = await Promise.all(allTasksId.map(async (id) => { + return await wex.ws.db.runReadOnlyTx( + ["operationRetries"], + async (tx) => { + return tx.operationRetries.get(id); + }, + ) + })) + + const tasks = allTasksId + .map((taskId, i): ActiveTask => { + const transaction = convertTaskToTransactionId(taskId); + const d = tasksInfo[i] + + const firstTry = !d?undefined:timestampAbsoluteFromDb(d.retryInfo.firstTry) + const nextTry = !d?undefined:timestampAbsoluteFromDb(d.retryInfo.nextRetry) + const counter = d?.retryInfo.retryCounter + const lastError = d?.lastError + + return { + id: taskId, counter, firstTry, nextTry, lastError, transaction + } + }) + return { tasks }; + } case WalletApiOperation.FailTransaction: { const req = codecForFailTransactionRequest().decode(payload); await failTransaction(wex, req.transactionId); @@ -1438,7 +1471,7 @@ async function handleCoreApiRequest( wex = getObservedWalletExecutionContext(ws, CancellationToken.CONTINUE, oc); } else { oc = { - observe(evt) {}, + observe(evt) { }, }; wex = getNormalWalletExecutionContext(ws, CancellationToken.CONTINUE, oc); } |