Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clan cache warmup #520 #526

Merged
merged 10 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/backend/AppKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const FileStore = require('session-file-store')(session)
const wordpressCacheCrawler = require('./cron-jobs/wordpressCacheCrawler')
const leaderboardCacheCrawler = require('./cron-jobs/leaderboardCacheCrawler')
const clanCacheCrawler = require('./cron-jobs/clanCacheCrawler')
const defaultRouter = require('./routes/views/defaultRouter')
const authRouter = require('./routes/views/auth')
const staticMarkdownRouter = require('./routes/views/staticMarkdownRouter')
Expand Down Expand Up @@ -122,6 +123,7 @@
startCronJobs () {
this.schedulers.push(leaderboardCacheCrawler(this.appContainer.get('LeaderboardService')))
this.schedulers.push(wordpressCacheCrawler(this.appContainer.get('WordpressService')))
this.schedulers.push(clanCacheCrawler(this.appContainer.get('ClanService')))

Check warning on line 126 in src/backend/AppKernel.js

View check run for this annotation

Codecov / codecov/patch

src/backend/AppKernel.js#L126

Added line #L126 was not covered by tests
}

loadControllers () {
Expand Down
35 changes: 35 additions & 0 deletions src/backend/cron-jobs/clanCacheCrawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Scheduler = require('../services/Scheduler')

const successHandler = (name) => {
console.debug('[debug] Cache updated', { name })

Check warning on line 4 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L4

Added line #L4 was not covered by tests
}
const errorHandler = (e, name) => {
console.error(e.toString(), { name, entrypoint: 'clanCacheCrawler.js' })
console.error(e.stack)

Check warning on line 8 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L7-L8

Added lines #L7 - L8 were not covered by tests
}

const warmupClans = async (clanService) => {
try {
await clanService.getAll(true)
.then(() => successHandler('clanService::getAll(global)'))
.catch((e) => errorHandler(e, 'clanService::getAll(global)'))

Check warning on line 15 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L12-L15

Added lines #L12 - L15 were not covered by tests
} catch (e) {
console.error('Error: clanCacheCrawler::warmupClans failed with "' + e.toString() + '"',

Check warning on line 17 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L17

Added line #L17 was not covered by tests
{ entrypoint: 'clanCacheCrawler.js' })
console.error(e.stack)

Check warning on line 19 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L19

Added line #L19 was not covered by tests
}
}

/**
* @param {clanService} clanService
* @return {Scheduler[]}
*/
module.exports = (clanService) => {
warmupClans(clanService).then(() => {})

Check warning on line 28 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L28

Added line #L28 was not covered by tests

const clansScheduler = new Scheduler('createClanCache', // Refresh cache every 59 minutes
() => warmupClans(clanService).then(() => {}), 60 * 59 * 1000)
clansScheduler.start()

Check warning on line 32 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L30-L32

Added lines #L30 - L32 were not covered by tests

return clansScheduler

Check warning on line 34 in src/backend/cron-jobs/clanCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/clanCacheCrawler.js#L34

Added line #L34 was not covered by tests
}
3 changes: 2 additions & 1 deletion src/backend/cron-jobs/leaderboardCacheCrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
module.exports = (leaderboardService) => {
warmupLeaderboard(leaderboardService).then(() => {})

const leaderboardScheduler = new Scheduler('createLeaderboardCaches', () => warmupLeaderboard(leaderboardService).then(() => {}), 60 * 59 * 1000)
const leaderboardScheduler = new Scheduler('createLeaderboardCaches',
() => warmupLeaderboard(leaderboardService).then(() => {}), 60 * 59 * 1000)

Check warning on line 42 in src/backend/cron-jobs/leaderboardCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/leaderboardCacheCrawler.js#L41-L42

Added lines #L41 - L42 were not covered by tests
leaderboardScheduler.start()

return leaderboardScheduler
Expand Down
6 changes: 3 additions & 3 deletions src/backend/cron-jobs/wordpressCacheCrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

/**
* @param {WordpressService} wordpressService
* @param {LeaderboardService} leaderboardService
* @return {Scheduler[]}
*/
module.exports = (wordpressService, leaderboardService) => {
module.exports = (wordpressService) => {
warmupWordpressCache(wordpressService)

const wordpressScheduler = new Scheduler('createWordpressCaches', () => warmupWordpressCache(wordpressService), 60 * 59 * 1000)
const wordpressScheduler = new Scheduler('createWordpressCaches',
() => warmupWordpressCache(wordpressService), 60 * 59 * 1000)

Check warning on line 46 in src/backend/cron-jobs/wordpressCacheCrawler.js

View check run for this annotation

Codecov / codecov/patch

src/backend/cron-jobs/wordpressCacheCrawler.js#L45-L46

Added lines #L45 - L46 were not covered by tests
wordpressScheduler.start()

return wordpressScheduler
Expand Down
2 changes: 1 addition & 1 deletion src/backend/services/ClanService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MutexService } = require('./MutexService')
const clanTTL = 60 * 5
const clanTTL = 60 * 60

class ClanService {
constructor (cacheService, dataRepository, lockTimeout = 3000) {
Expand Down