gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: simplify retry timeout handli


From: gnunet
Subject: [taler-wallet-core] branch master updated: simplify retry timeout handling
Date: Fri, 11 Jun 2021 11:15:14 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new e7751010 simplify retry timeout handling
e7751010 is described below

commit e77510106fdcb0448af809fd6c928f1ff80b6d15
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Jun 11 11:15:08 2021 +0200

    simplify retry timeout handling
---
 packages/taler-wallet-core/src/db.ts                  |  2 +-
 packages/taler-wallet-core/src/operations/deposits.ts |  2 +-
 packages/taler-wallet-core/src/operations/pay.ts      |  4 ++--
 packages/taler-wallet-core/src/operations/pending.ts  |  3 ++-
 packages/taler-wallet-core/src/operations/recoup.ts   |  2 +-
 packages/taler-wallet-core/src/operations/refresh.ts  |  2 +-
 packages/taler-wallet-core/src/operations/refund.ts   |  2 +-
 packages/taler-wallet-core/src/operations/reserves.ts |  2 +-
 packages/taler-wallet-core/src/operations/tip.ts      |  2 +-
 packages/taler-wallet-core/src/operations/withdraw.ts |  2 +-
 packages/taler-wallet-core/src/pending-types.ts       |  2 +-
 packages/taler-wallet-core/src/util/retries.ts        | 16 +++++-----------
 12 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index ca613e5e..fb242e37 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -922,7 +922,7 @@ export interface ProposalRecord {
    * Retry info, even present when the operation isn't active to allow indexing
    * on the next retry timestamp.
    */
-  retryInfo: RetryInfo;
+  retryInfo?: RetryInfo;
 
   lastError: TalerErrorDetails | undefined;
 }
diff --git a/packages/taler-wallet-core/src/operations/deposits.ts 
b/packages/taler-wallet-core/src/operations/deposits.ts
index 996e8cf3..23cc435f 100644
--- a/packages/taler-wallet-core/src/operations/deposits.ts
+++ b/packages/taler-wallet-core/src/operations/deposits.ts
@@ -123,7 +123,7 @@ async function resetDepositGroupRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.depositGroups.get(depositGroupId);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.depositGroups.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/pay.ts 
b/packages/taler-wallet-core/src/operations/pay.ts
index cbb92dc8..39adad70 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -555,7 +555,7 @@ async function resetDownloadProposalRetry(
     .mktx((x) => ({ proposals: x.proposals }))
     .runReadWrite(async (tx) => {
       const p = await tx.proposals.get(proposalId);
-      if (p && p.retryInfo.active) {
+      if (p) {
         p.retryInfo = initRetryInfo();
         await tx.proposals.put(p);
       }
@@ -574,7 +574,7 @@ async function failProposalPermanently(
       if (!p) {
         return;
       }
-      p.retryInfo.active = false;
+      delete p.retryInfo;
       p.lastError = err;
       p.proposalStatus = ProposalStatus.PERMANENTLY_FAILED;
       await tx.proposals.put(p);
diff --git a/packages/taler-wallet-core/src/operations/pending.ts 
b/packages/taler-wallet-core/src/operations/pending.ts
index b40c33c5..f0c9c9d8 100644
--- a/packages/taler-wallet-core/src/operations/pending.ts
+++ b/packages/taler-wallet-core/src/operations/pending.ts
@@ -155,10 +155,11 @@ async function gatherProposalPending(
     if (proposal.proposalStatus == ProposalStatus.PROPOSED) {
       // Nothing to do, user needs to choose.
     } else if (proposal.proposalStatus == ProposalStatus.DOWNLOADING) {
+      const timestampDue = proposal.retryInfo?.nextRetry ?? getTimestampNow();
       resp.pendingOperations.push({
         type: PendingOperationType.ProposalDownload,
         givesLifeness: true,
-        timestampDue: proposal.retryInfo.nextRetry,
+        timestampDue,
         merchantBaseUrl: proposal.merchantBaseUrl,
         orderId: proposal.orderId,
         proposalId: proposal.proposalId,
diff --git a/packages/taler-wallet-core/src/operations/recoup.ts 
b/packages/taler-wallet-core/src/operations/recoup.ts
index 7dac7faf..24ac828f 100644
--- a/packages/taler-wallet-core/src/operations/recoup.ts
+++ b/packages/taler-wallet-core/src/operations/recoup.ts
@@ -316,7 +316,7 @@ async function resetRecoupGroupRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.recoupGroups.get(recoupGroupId);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.recoupGroups.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts 
b/packages/taler-wallet-core/src/operations/refresh.ts
index 21c92c1b..0b0eb4c4 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -656,7 +656,7 @@ async function resetRefreshGroupRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.refreshGroups.get(refreshGroupId);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.refreshGroups.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/refund.ts 
b/packages/taler-wallet-core/src/operations/refund.ts
index ba0674f0..b3d368af 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -589,7 +589,7 @@ async function resetPurchaseQueryRefundRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.purchases.get(proposalId);
-      if (x && x.refundStatusRetryInfo.active) {
+      if (x) {
         x.refundStatusRetryInfo = initRetryInfo();
         await tx.purchases.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/reserves.ts 
b/packages/taler-wallet-core/src/operations/reserves.ts
index 6f531820..998fbf3e 100644
--- a/packages/taler-wallet-core/src/operations/reserves.ts
+++ b/packages/taler-wallet-core/src/operations/reserves.ts
@@ -85,7 +85,7 @@ async function resetReserveRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.reserves.get(reservePub);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.reserves.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/tip.ts 
b/packages/taler-wallet-core/src/operations/tip.ts
index e9659248..b96a8fce 100644
--- a/packages/taler-wallet-core/src/operations/tip.ts
+++ b/packages/taler-wallet-core/src/operations/tip.ts
@@ -208,7 +208,7 @@ async function resetTipRetry(
     }))
     .runReadWrite(async (tx) => {
       const x = await tx.tips.get(tipId);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.tips.put(x);
       }
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts 
b/packages/taler-wallet-core/src/operations/withdraw.ts
index 1266a3b0..9f5c225f 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -790,7 +790,7 @@ async function resetWithdrawalGroupRetry(
     .mktx((x) => ({ withdrawalGroups: x.withdrawalGroups }))
     .runReadWrite(async (tx) => {
       const x = await tx.withdrawalGroups.get(withdrawalGroupId);
-      if (x && x.retryInfo.active) {
+      if (x) {
         x.retryInfo = initRetryInfo();
         await tx.withdrawalGroups.put(x);
       }
diff --git a/packages/taler-wallet-core/src/pending-types.ts 
b/packages/taler-wallet-core/src/pending-types.ts
index 5586903f..8198d439 100644
--- a/packages/taler-wallet-core/src/pending-types.ts
+++ b/packages/taler-wallet-core/src/pending-types.ts
@@ -132,7 +132,7 @@ export interface PendingProposalDownloadOperation {
   proposalId: string;
   orderId: string;
   lastError?: TalerErrorDetails;
-  retryInfo: RetryInfo;
+  retryInfo?: RetryInfo;
 }
 
 /**
diff --git a/packages/taler-wallet-core/src/util/retries.ts 
b/packages/taler-wallet-core/src/util/retries.ts
index a7f4cd28..b8684624 100644
--- a/packages/taler-wallet-core/src/util/retries.ts
+++ b/packages/taler-wallet-core/src/util/retries.ts
@@ -27,7 +27,6 @@ export interface RetryInfo {
   firstTry: Timestamp;
   nextRetry: Timestamp;
   retryCounter: number;
-  active: boolean;
 }
 
 export interface RetryPolicy {
@@ -52,16 +51,19 @@ export function updateRetryInfoTimeout(
     r.nextRetry = { t_ms: "never" };
     return;
   }
-  r.active = true;
   const t =
     now.t_ms + p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter);
   r.nextRetry = { t_ms: t };
 }
 
 export function getRetryDuration(
-  r: RetryInfo,
+  r: RetryInfo | undefined,
   p: RetryPolicy = defaultRetryPolicy,
 ): Duration {
+  if (!r) {
+    // If we don't have any retry info, run immediately.
+    return { d_ms: 0 };
+  }
   if (p.backoffDelta.d_ms === "forever") {
     return { d_ms: "forever" };
   }
@@ -73,14 +75,6 @@ export function initRetryInfo(
   active = true,
   p: RetryPolicy = defaultRetryPolicy,
 ): RetryInfo {
-  if (!active) {
-    return {
-      active: false,
-      firstTry: { t_ms: Number.MAX_SAFE_INTEGER },
-      nextRetry: { t_ms: Number.MAX_SAFE_INTEGER },
-      retryCounter: 0,
-    };
-  }
   const now = getTimestampNow();
   const info = {
     firstTry: now,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]