|
@@ -116,6 +116,9 @@ const getStraightFixtures = async () => {
|
|
|
since = 0;
|
|
since = 0;
|
|
|
GLOBAL_DATA.straightFixturesCount = 0;
|
|
GLOBAL_DATA.straightFixturesCount = 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (since == 0) {
|
|
|
|
|
+ Logs.outDev('full update straight fixtures');
|
|
|
|
|
+ }
|
|
|
return pinnacleGet('/v3/fixtures', { sportId: 29, leagueIds, since })
|
|
return pinnacleGet('/v3/fixtures', { sportId: 29, leagueIds, since })
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
const { league, last } = data;
|
|
const { league, last } = data;
|
|
@@ -155,7 +158,6 @@ const updateStraightFixtures = async () => {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
if (update && update == 'full') {
|
|
if (update && update == 'full') {
|
|
|
- Logs.outDev('full update straight fixtures');
|
|
|
|
|
const gamesSet = new Set(games.map(game => game.id));
|
|
const gamesSet = new Set(games.map(game => game.id));
|
|
|
Object.keys(gamesMap).forEach(key => {
|
|
Object.keys(gamesMap).forEach(key => {
|
|
|
if (!gamesSet.has(+key)) {
|
|
if (!gamesSet.has(+key)) {
|
|
@@ -211,6 +213,9 @@ const getSpecialFixtures = async () => {
|
|
|
since = 0;
|
|
since = 0;
|
|
|
GLOBAL_DATA.specialFixturesCount = 6;
|
|
GLOBAL_DATA.specialFixturesCount = 6;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (since == 0) {
|
|
|
|
|
+ Logs.outDev('full update special fixtures');
|
|
|
|
|
+ }
|
|
|
return pinnacleGet('/v2/fixtures/special', { sportId: 29, leagueIds, since })
|
|
return pinnacleGet('/v2/fixtures/special', { sportId: 29, leagueIds, since })
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
const { leagues, last } = data;
|
|
const { leagues, last } = data;
|
|
@@ -318,9 +323,6 @@ const updateSpecialFixtures = async () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- if (update && update == 'full') {
|
|
|
|
|
- Logs.outDev('full update special fixtures');
|
|
|
|
|
- }
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -624,13 +626,21 @@ const pinnacleDataLoop = () => {
|
|
|
return updateSpecialsOdds();
|
|
return updateSpecialsOdds();
|
|
|
})
|
|
})
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
|
|
+ if (!GLOBAL_DATA.loopActive) {
|
|
|
|
|
+ GLOBAL_DATA.loopActive = true;
|
|
|
|
|
+ Logs.out('loop active');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (GLOBAL_DATA.requestErrorCount > 0) {
|
|
|
|
|
+ GLOBAL_DATA.requestErrorCount = 0;
|
|
|
|
|
+ Logs.out('request error count reset');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const nowTime = Date.now();
|
|
const nowTime = Date.now();
|
|
|
const loopDuration = nowTime - GLOBAL_DATA.loopResultTime;
|
|
const loopDuration = nowTime - GLOBAL_DATA.loopResultTime;
|
|
|
GLOBAL_DATA.loopResultTime = nowTime;
|
|
GLOBAL_DATA.loopResultTime = nowTime;
|
|
|
Logs.outDev('loop duration', loopDuration);
|
|
Logs.outDev('loop duration', loopDuration);
|
|
|
|
|
|
|
|
- GLOBAL_DATA.requestErrorCount = 0;
|
|
|
|
|
-
|
|
|
|
|
const { straightFixturesVersion: sfv, specialFixturesVersion: pfv, straightOddsVersion: sov, specialsOddsVersion: pov } = GLOBAL_DATA;
|
|
const { straightFixturesVersion: sfv, specialFixturesVersion: pfv, straightOddsVersion: sov, specialsOddsVersion: pov } = GLOBAL_DATA;
|
|
|
const timestamp = Math.max(sfv, pfv, sov, pov);
|
|
const timestamp = Math.max(sfv, pfv, sov, pov);
|
|
|
const games = getGames();
|
|
const games = getGames();
|
|
@@ -641,20 +651,32 @@ const pinnacleDataLoop = () => {
|
|
|
writeFileSync(cacheFilePath, JSON.stringify(GLOBAL_DATA.gamesMap, null, 2));
|
|
writeFileSync(cacheFilePath, JSON.stringify(GLOBAL_DATA.gamesMap, null, 2));
|
|
|
})
|
|
})
|
|
|
.catch(err => {
|
|
.catch(err => {
|
|
|
|
|
+ Logs.err(err.message, err.source);
|
|
|
GLOBAL_DATA.requestErrorCount++;
|
|
GLOBAL_DATA.requestErrorCount++;
|
|
|
- if (GLOBAL_DATA.requestErrorCount > 10) {
|
|
|
|
|
|
|
+ if (GLOBAL_DATA.loopActive && GLOBAL_DATA.requestErrorCount > 5) {
|
|
|
GLOBAL_DATA.loopActive = false;
|
|
GLOBAL_DATA.loopActive = false;
|
|
|
|
|
+ Logs.out('loop inactive');
|
|
|
notifyException('Pinnacle API request errors have reached the limit.');
|
|
notifyException('Pinnacle API request errors have reached the limit.');
|
|
|
}
|
|
}
|
|
|
- Logs.err(err.message, err.source);
|
|
|
|
|
})
|
|
})
|
|
|
.finally(() => {
|
|
.finally(() => {
|
|
|
- if (!GLOBAL_DATA.loopActive) {
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ const { loopActive } = GLOBAL_DATA;
|
|
|
|
|
+ let loopDelay = 1000 * 5;
|
|
|
|
|
+ if (!loopActive) {
|
|
|
|
|
+ loopDelay = 1000 * 60;
|
|
|
|
|
+ GLOBAL_DATA.straightFixturesVersion = 0;
|
|
|
|
|
+ GLOBAL_DATA.specialFixturesVersion = 0;
|
|
|
|
|
+ GLOBAL_DATA.straightOddsVersion = 0;
|
|
|
|
|
+ GLOBAL_DATA.specialsOddsVersion = 0;
|
|
|
|
|
+
|
|
|
|
|
+ GLOBAL_DATA.straightFixturesCount = 0;
|
|
|
|
|
+ GLOBAL_DATA.specialFixturesCount = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ GLOBAL_DATA.straightFixturesCount++;
|
|
|
|
|
+ GLOBAL_DATA.specialFixturesCount++;
|
|
|
}
|
|
}
|
|
|
- GLOBAL_DATA.straightFixturesCount++;
|
|
|
|
|
- GLOBAL_DATA.specialFixturesCount++;
|
|
|
|
|
- setTimeout(pinnacleDataLoop, 1000 * 5);
|
|
|
|
|
|
|
+ setTimeout(pinnacleDataLoop, loopDelay);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|