simplify retry timeout handling
This commit is contained in:
parent
8ad36d89f5
commit
e77510106f
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ export interface PendingProposalDownloadOperation {
|
||||
proposalId: string;
|
||||
orderId: string;
|
||||
lastError?: TalerErrorDetails;
|
||||
retryInfo: RetryInfo;
|
||||
retryInfo?: RetryInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user