fix never ending solana jobs
This commit is contained in:
parent
4d71c0038c
commit
460e17f849
|
@ -22,7 +22,11 @@
|
|||
"network": "devnet",
|
||||
"chainId": 1,
|
||||
"rpcs": ["https://api.devnet.solana.com"],
|
||||
"timeout": 10000
|
||||
"timeout": 10000,
|
||||
"rateLimit": {
|
||||
"period": 10000,
|
||||
"limit": 40
|
||||
}
|
||||
},
|
||||
"ethereum": {
|
||||
"name": "ethereum",
|
||||
|
|
|
@ -32,7 +32,7 @@ export abstract class RunPollingJob {
|
|||
items = await this.get();
|
||||
await Promise.all(handlers.map((handler) => handler(items)));
|
||||
} catch (e: Error | any) {
|
||||
this.logger.error("Error processing items", e.stack ?? e);
|
||||
this.logger.error("Error processing items", e, e.stack);
|
||||
await setTimeout(this.interval);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ export class PollSolanaTransactions extends RunPollingJob {
|
|||
}
|
||||
}
|
||||
|
||||
protected async hasNext(): Promise<boolean> {
|
||||
if (this.cfg.toSlot && this.slotCursor && this.slotCursor > this.cfg.toSlot) {
|
||||
async hasNext(): Promise<boolean> {
|
||||
if (this.cfg.toSlot && this.slotCursor && this.slotCursor >= this.cfg.toSlot) {
|
||||
this.logger.info(
|
||||
`Finished processing all slots from ${this.cfg.fromSlot} to ${this.cfg.toSlot}`
|
||||
);
|
||||
|
@ -68,7 +68,8 @@ export class PollSolanaTransactions extends RunPollingJob {
|
|||
|
||||
// signatures for address goes back from current sig
|
||||
const afterSignature = fromBlock.transactions[0]?.transaction.signatures[0];
|
||||
let beforeSignature = toBlock.transactions[0]?.transaction.signatures[0];
|
||||
let beforeSignature =
|
||||
toBlock.transactions[toBlock.transactions.length - 1]?.transaction.signatures[0];
|
||||
if (!afterSignature || !beforeSignature) {
|
||||
throw new Error(
|
||||
`No signature presents in transactions. After: ${afterSignature}. Before: ${beforeSignature} [slots: ${range.fromSlot} - ${range.toSlot}]`
|
||||
|
|
|
@ -96,10 +96,35 @@ describe("PollSolanaTransactions", () => {
|
|||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("should be able to read transactions from last known slot and stop when toSlot is reached", async () => {
|
||||
const latestSlot = 100;
|
||||
const lastSlot = 10;
|
||||
const toSlot = 50;
|
||||
const expectedSigs = givenSigs();
|
||||
const expectedTxs = givenTxs();
|
||||
|
||||
givenCfg({ toSlot });
|
||||
givenStatsRepository();
|
||||
givenMetadataRepository({ lastSlot });
|
||||
givenSolanaSlotRepository(latestSlot, givenBlock(1), expectedSigs, expectedTxs);
|
||||
givenPollSolanaTransactions();
|
||||
|
||||
pollSolanaTransactions.run([handlers.working]);
|
||||
|
||||
await thenWaitForAssertion(
|
||||
() =>
|
||||
expect(metadataSaveSpy).toHaveBeenCalledWith(cfg.id, {
|
||||
lastSlot: toSlot,
|
||||
}),
|
||||
() => expect(pollSolanaTransactions.hasNext()).resolves.toBe(false)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const givenCfg = () => {
|
||||
const givenCfg = (overrides?: Partial<PollSolanaTransactionsConfig>) => {
|
||||
cfg = new PollSolanaTransactionsConfig("anId", "programID", "confirmed");
|
||||
Object.assign(cfg, overrides);
|
||||
};
|
||||
|
||||
const givenMetadataRepository = (data?: PollSolanaTransactionsMetadata) => {
|
||||
|
|
Loading…
Reference in New Issue