Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olivbau committed Dec 27, 2024
1 parent 52380cd commit 92c1c57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ type GeckoCoin = {
platforms?: { [key: string]: string };
};

const COINS_LIST_TTL = 21600000; // 6h
const COINS_LIST_TTL = 86400000; // 24h
let gCoinsList: GeckoCoin[] | undefined;
let gCoinsListTs = 0;

export async function getCoingeckoCoinsList() {
await sleep(300000);
await sleep(5000);

if (gCoinsList && Date.now() - COINS_LIST_TTL < gCoinsListTs)
return gCoinsList;
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/coingeckoJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import axios, { AxiosResponse } from 'axios';
import { sleep } from '../helpers/misc';
import { Token, JobFct, Job } from '../types';
import { getCoingeckoCoinsList } from '../helpers/getCoingeckoCoinList';
import { getCoingeckoCoinsList } from '../helpers/getCoingeckoCoinsList';
import { constTokensMap } from '../tokens/constTokens';
import { getKey } from '../helpers/getKey';

Expand Down
17 changes: 17 additions & 0 deletions tests/getCoingeckoCoinsList.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getCoingeckoCoinsList } from '../src/helpers/getCoingeckoCoinsList';

describe('getCoingeckoCoinsList', () => {
jest.setTimeout(1200000); // Increase the timeout to handle potential network delays
it('sould getCoingeckoCoinsList', async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const list1 = await getCoingeckoCoinsList();

const debut = performance.now();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const list2 = await getCoingeckoCoinsList();
const fin = performance.now();
const tempsEcoule = fin - debut;

expect(tempsEcoule).toBeLessThan(1000);
});
});

0 comments on commit 92c1c57

Please sign in to comment.