Skip to content

Commit

Permalink
chore(indexer): reduce provider status retry interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Aug 5, 2024
1 parent fa1f252 commit a3748f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions apps/indexer/src/providers/providerStatusProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AkashBlock,
Provider,
ProviderSnapshot,
ProviderSnapshotNode,
Expand Down Expand Up @@ -30,6 +31,7 @@ export async function syncProvidersInfo() {
nextCheckDate: { [Op.lte]: toUTC(new Date()) }
},
include: [
{ model: AkashBlock, as: "createdBlock" },
{ model: ProviderSnapshot, as: "lastSnapshot" },
{ model: ProviderSnapshot, as: "downtimeFirstSnapshot" }
],
Expand Down Expand Up @@ -151,7 +153,12 @@ async function saveProviderStatus(
error: error,
lastCheckDate: checkDate,
failedCheckCount: providerStatus ? 0 : provider.failedCheckCount + 1,
nextCheckDate: getNextCheckDate(!!providerStatus, checkDate, provider.downtimeFirstSnapshot?.checkDate ?? createdSnapshot.checkDate),
nextCheckDate: getNextCheckDate(
!!providerStatus,
checkDate,
provider.downtimeFirstSnapshot?.checkDate ?? createdSnapshot.checkDate,
provider.createdBlock.datetime
),
cosmosSdkVersion: cosmosVersion,
akashVersion: akashVersion
},
Expand Down Expand Up @@ -220,20 +227,22 @@ async function saveProviderStatus(
});
}

function getNextCheckDate(successful: boolean, checkDate: Date, downtimeStartDate: Date) {
function getNextCheckDate(successful: boolean, checkDate: Date, downtimeStartDate: Date, createdOn: Date) {
if (successful) {
return add(checkDate, { seconds: UptimeCheckIntervalSeconds });
}

if (differenceInMinutes(checkDate, downtimeStartDate) < 15) {
const wasCreatedRecently = differenceInDays(checkDate, createdOn) < 7;

if (differenceInMinutes(checkDate, downtimeStartDate) < 30) {
return add(checkDate, { minutes: 1 });
} else if (differenceInHours(checkDate, downtimeStartDate) < 1) {
} else if (differenceInHours(checkDate, downtimeStartDate) < 6 || wasCreatedRecently) {
return add(checkDate, { minutes: 5 });
} else if (differenceInHours(checkDate, downtimeStartDate) < 6) {
return add(checkDate, { minutes: 15 });
} else if (differenceInHours(checkDate, downtimeStartDate) < 24) {
return add(checkDate, { minutes: 30 });
return add(checkDate, { minutes: 15 });
} else if (differenceInDays(checkDate, downtimeStartDate) < 7) {
return add(checkDate, { minutes: 30 });
} else if (differenceInDays(checkDate, downtimeStartDate) < 30) {
return add(checkDate, { hours: 1 });
} else {
return add(checkDate, { hours: 24 });
Expand Down
2 changes: 2 additions & 0 deletions packages/database/dbSchemas/akash/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Required } from "../decorators/requiredDecorator";
import { ProviderAttribute } from "./providerAttribute";
import { ProviderAttributeSignature } from "./providerAttributeSignature";
import { ProviderSnapshot } from "./providerSnapshot";
import { AkashBlock } from "./akashBlock";

@Table({
modelName: "provider",
Expand Down Expand Up @@ -45,6 +46,7 @@ export class Provider extends Model {
@HasMany(() => ProviderAttribute, "provider") providerAttributes: ProviderAttribute[];
@HasMany(() => ProviderAttributeSignature, "provider") providerAttributeSignatures: ProviderAttributeSignature[];
@HasMany(() => ProviderSnapshot, "owner") providerSnapshots: ProviderSnapshot[];
@BelongsTo(() => AkashBlock, "createdHeight") createdBlock: AkashBlock;
@BelongsTo(() => ProviderSnapshot, "lastSnapshotId") lastSnapshot: ProviderSnapshot;
@BelongsTo(() => ProviderSnapshot, "lastSuccessfulSnapshotId") lastSuccessfulSnapshot: ProviderSnapshot;
@BelongsTo(() => ProviderSnapshot, "downtimeFirstSnapshotId") downtimeFirstSnapshot: ProviderSnapshot;
Expand Down

0 comments on commit a3748f1

Please sign in to comment.