Skip to content

Commit

Permalink
🐛 Error catching during stats + erpc config
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jul 24, 2024
1 parent fa0ff61 commit 9a7927a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 38 deletions.
11 changes: 11 additions & 0 deletions iac/Erpc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Duration } from "aws-cdk-lib";
import { Repository } from "aws-cdk-lib/aws-ecr";
import { ContainerImage } from "aws-cdk-lib/aws-ecs";
import { Service, type StackContext, use } from "sst/constructs";
Expand Down Expand Up @@ -80,6 +81,16 @@ export function ErpcStack({ app, stack }: StackContext) {
containerName: "erpc",
image: erpcImage,
secrets: cdkSecretsMap,
healthCheck: {
command: [
"CMD-SHELL",
"curl -f http://localhost:4001 || exit 1",
],
interval: Duration.seconds(30),
timeout: Duration.seconds(15),
retries: 3,
startPeriod: Duration.seconds(30),
},
},
},
});
Expand Down
10 changes: 10 additions & 0 deletions iac/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export function IndexerStack({ app, stack }: StackContext) {
containerName: "indexer",
image: indexerImage,
secrets: cdkSecretsMap,
/*healthCheck: {
command: [
"CMD-SHELL",
"curl -f http://localhost:42069/status || exit 1",
],
interval: Duration.seconds(30),
timeout: Duration.seconds(5),
retries: 3,
startPeriod: Duration.seconds(30),
},*/
},
},
});
Expand Down
38 changes: 32 additions & 6 deletions packages/erpc/erpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,40 @@ projects:
delay: 1000ms
maxCount: 2
upstreams:
- id: alchemy-multi-chain
endpoint: alchemy://${ALCHEMY_API_KEY}
# todo: Disabled for now since api endpoints seems to be fcked up
# - id: alchemy-multi-chain
# endpoint: alchemy://${ALCHEMY_API_KEY}
# type: evm-alchemy
# rateLimitBudget: alchemy
# healthCheckGroup: default-hcg
# failsafe:
# timeout:
# duration: 15s
# retry:
# maxCount: 2
# delay: 1000ms
# backoffMaxDelay: 10s
# backoffFactor: 0.3
# jitter: 500ms
- id: alchemy-arb-sepolia
endpoint: https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}
type: evm-alchemy
rateLimitBudget: alchemy
healthCheckGroup: default-hcg
failsafe:
timeout:
duration: 15s
retry:
maxCount: 2
delay: 1000ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
- id: alchemy-arb
endpoint: https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}
type: evm-alchemy
rateLimitBudget: alchemy
healthCheckGroup: default-hcg
allowMethods:
- "alchemy_*"
ignoreMethods:
- "trace_transaction"
failsafe:
timeout:
duration: 15s
Expand Down
71 changes: 39 additions & 32 deletions packages/ponder/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,44 @@ export async function increaseCampaignsInteractions({
console.error("Campaign id not found", campaign);
continue;
}
// Create the stats if not found
await PressCampaignStats.upsert({
id: campaign.id,
create: {
campaignId: campaign.id,
totalInteractions: 0n,
openInteractions: 0n,
readInteractions: 0n,
referredInteractions: 0n,
createReferredLinkInteractions: 0n,
totalRewards: 0n,
},
// Update the given field by incrementing them
update: ({ current }) => {
return {
...current,
totalInteractions: current.totalInteractions + 1n,
openInteractions:
current.openInteractions +
(increments.openInteractions ?? 0n),
readInteractions:
current.readInteractions +
(increments.readInteractions ?? 0n),
referredInteractions:
current.referredInteractions +
(increments.referredInteractions ?? 0n),
createReferredLinkInteractions:
current.createReferredLinkInteractions +
(increments.createReferredLinkInteractions ?? 0n),
};
},
});
try {
// Create the stats if not found
await PressCampaignStats.upsert({
id: campaign.id,
create: {
campaignId: campaign.id,
totalInteractions: 0n,
openInteractions: 0n,
readInteractions: 0n,
referredInteractions: 0n,
createReferredLinkInteractions: 0n,
totalRewards: 0n,
},
// Update the given field by incrementing them
update: ({ current }) => {
return {
...current,
totalInteractions: current.totalInteractions + 1n,
openInteractions:
current.openInteractions +
(increments.openInteractions ?? 0n),
readInteractions:
current.readInteractions +
(increments.readInteractions ?? 0n),
referredInteractions:
current.referredInteractions +
(increments.referredInteractions ?? 0n),
createReferredLinkInteractions:
current.createReferredLinkInteractions +
(increments.createReferredLinkInteractions ?? 0n),
};
},
});
} catch (error) {
console.error("Error while incrementing campaign stats", error, {
campaign,
increments,
});
}
}
}

0 comments on commit 9a7927a

Please sign in to comment.