summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-06-11 11:15:08 +0200
committerFlorian Dold <florian@dold.me>2021-06-11 11:15:08 +0200
commite77510106fdcb0448af809fd6c928f1ff80b6d15 (patch)
tree7aeb34586b4ae86d578090da296de0050e723328 /packages
parent8ad36d89f55783c34043ee9ef37759cd94bcec7c (diff)
downloadwallet-core-e77510106fdcb0448af809fd6c928f1ff80b6d15.tar.gz
wallet-core-e77510106fdcb0448af809fd6c928f1ff80b6d15.tar.bz2
wallet-core-e77510106fdcb0448af809fd6c928f1ff80b6d15.zip
simplify retry timeout handling
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/db.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/deposits.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/pay.ts4
-rw-r--r--packages/taler-wallet-core/src/operations/pending.ts3
-rw-r--r--packages/taler-wallet-core/src/operations/recoup.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/refresh.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/refund.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/reserves.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/tip.ts2
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts2
-rw-r--r--packages/taler-wallet-core/src/pending-types.ts2
-rw-r--r--packages/taler-wallet-core/src/util/retries.ts16
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 ca613e5e5..fb242e379 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 996e8cf39..23cc435ff 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 cbb92dc86..39adad70e 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 b40c33c5c..f0c9c9d8c 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 7dac7faf4..24ac828f3 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 21c92c1b7..0b0eb4c4a 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 ba0674f06..b3d368afa 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 6f531820c..998fbf3e0 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 e9659248d..b96a8fcef 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 1266a3b0f..9f5c225fc 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 5586903f5..8198d439f 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 a7f4cd281..b86846244 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,