Skip to content

Commit

Permalink
[MIM-1707] Wrap most cron jobs in isMaster so no duplicate work is do…
Browse files Browse the repository at this point in the history
…ne (#2318)

Wrap most cron jobs in isMaster so no duplicate work is done
  • Loading branch information
omsaggau authored Dec 6, 2023
1 parent 1421a35 commit b827f95
Showing 1 changed file with 129 additions and 129 deletions.
258 changes: 129 additions & 129 deletions src/main/resources/lib/ssb/cron/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,27 @@ export function runOnMasterOnly(task: () => void): void {
export function setupCronJobs(): void {
run(createUserContext, setupCronJobUser)

// setup dataquery cron job
const dataqueryCron: string =
app.config && app.config['ssb.cron.dataquery'] ? app.config['ssb.cron.dataquery'] : '0 15 * * *'
// clear specific cache once an hour
const clearCacheCron: string =
app.config && app.config['ssb.cron.clearCacheCron'] ? app.config['ssb.cron.clearCacheCron'] : '01 * * * *'
schedule({
name: 'Data from datasource endpoints',
cron: dataqueryCron,
name: 'clear cache',
cron: clearCacheCron,
callback: () => {
libScheduleTestLog('dataqueryCronTest', dataqueryCron)
runOnMasterOnly(job)
clearPartFromPartCache('kpiCalculator')
clearPartFromPartCache('pifCalculator')
clearPartFromPartCache('bkibolCalculator')
clearPartFromPartCache('husleieCalculator')
clearPartFromPartCache('omStatistikken')
clearPartFromPartCache('releasedStatistics')
clearPartFromPartCache('upcomingReleases')
clearPartFromPartCache('articleList')
clearPartFromPartCache('relatedFactPage')
clearPartFromPartCache('archiveAllPublications-nb')
clearPartFromPartCache('archiveAllPublications-en')
},
context: cronContext,
})
// using config in https://github.com/statisticsnorway/mimir-config/blob/master/prod/mimir.cfg as base
libScheduleTest({ name: 'dataqueryCronTest', cron: '03 08 * * *', timeZone: 'Europe/Oslo' }, dataqueryCron)

// clear calculator parts cache cron
const clearCalculatorPartsCacheCron: string =
Expand All @@ -189,140 +196,133 @@ export function setupCronJobs(): void {
},
context: cronContext,
})
libScheduleTest(
{ name: 'clearCalculatorCronTest', cron: '15 08 * * *', timeZone: 'Europe/Oslo' },
clearCalculatorPartsCacheCron
)

// and setup a cron for periodic executions in the future
const statregCron: string =
app.config && app.config['ssb.cron.statreg'] ? app.config['ssb.cron.statreg'] : '30 14 * * *'
schedule({
name: 'StatReg Periodic Refresh',
cron: statregCron,
callback: () => {
libScheduleTestLog('statregRefreshCronTest', statregCron)
runOnMasterOnly(statRegJob)
},
context: cronContext,
})
libScheduleTest({ name: 'statregRefreshCronTest', cron: '05 8 * * *', timeZone: 'Europe/Oslo' }, statregCron)
if (isMaster()) {
// setup dataquery cron job
const dataqueryCron: string =
app.config && app.config['ssb.cron.dataquery'] ? app.config['ssb.cron.dataquery'] : '0 15 * * *'
schedule({
name: 'Data from datasource endpoints',
cron: dataqueryCron,
callback: () => {
libScheduleTestLog('dataqueryCronTest', dataqueryCron)
job()
},
context: cronContext,
})
// using config in https://github.com/statisticsnorway/mimir-config/blob/master/prod/mimir.cfg as base
libScheduleTest({ name: 'dataqueryCronTest', cron: '03 08 * * *', timeZone: 'Europe/Oslo' }, dataqueryCron)

// Update repo no.ssb.statistic.variant
const updateStatisticRepoCron: string =
app.config && app.config['ssb.cron.updateStatisticRepo'] ? app.config['ssb.cron.updateStatisticRepo'] : '0 7 * * *'
// and setup a cron for periodic executions in the future
const statregCron: string =
app.config && app.config['ssb.cron.statreg'] ? app.config['ssb.cron.statreg'] : '30 14 * * *'
schedule({
name: 'StatReg Periodic Refresh',
cron: statregCron,
callback: () => {
libScheduleTestLog('statregRefreshCronTest', statregCron)
statRegJob()
},
context: cronContext,
})
libScheduleTest({ name: 'statregRefreshCronTest', cron: '05 8 * * *', timeZone: 'Europe/Oslo' }, statregCron)

schedule({
name: 'Update no.ssb.statistics Repo',
cron: updateStatisticRepoCron,
callback: () => {
libScheduleTestLog('statregUpdateCronTest', updateStatisticRepoCron)
runOnMasterOnly(createOrUpdateStatisticsRepo)
},
context: cronContext,
})
libScheduleTest(
{ name: 'statregUpdateCronTest', cron: '0 8 * * *', timeZone: 'Europe/Oslo' },
updateStatisticRepoCron
)
// Update repo no.ssb.statistic.variant
const updateStatisticRepoCron: string =
app.config && app.config['ssb.cron.updateStatisticRepo']
? app.config['ssb.cron.updateStatisticRepo']
: '0 7 * * *'

const deleteExpiredEventLogCron: string =
app.config && app.config['ssb.cron.deleteLogs'] ? app.config['ssb.cron.deleteLogs'] : '45 13 * * *'
schedule({
name: 'Delete expired event logs for queries',
cron: deleteExpiredEventLogCron,
callback: () => {
libScheduleTestLog('deleteExpireCronTest', deleteExpiredEventLogCron)
runOnMasterOnly(deleteExpiredEventLogsForQueries)
},
context: cronContext,
})
libScheduleTest(
{ name: 'deleteExpireCronTest', cron: '20 15 * * *', timeZone: 'Europe/Oslo' },
deleteExpiredEventLogCron
)
schedule({
name: 'Update no.ssb.statistics Repo',
cron: updateStatisticRepoCron,
callback: () => {
libScheduleTestLog('statregUpdateCronTest', updateStatisticRepoCron)
createOrUpdateStatisticsRepo()
},
context: cronContext,
})
libScheduleTest(
{ name: 'statregUpdateCronTest', cron: '0 8 * * *', timeZone: 'Europe/Oslo' },
updateStatisticRepoCron
)

if (app.config && app.config['ssb.mock.enable'] === 'true') {
const updateUnpublishedMockCron: string =
app.config && app.config['ssb.cron.updateUnpublishedMock']
? app.config['ssb.cron.updateUnpublishedMock']
: '0 04 * * *'
const deleteExpiredEventLogCron: string =
app.config && app.config['ssb.cron.deleteLogs'] ? app.config['ssb.cron.deleteLogs'] : '45 13 * * *'
schedule({
name: 'Update unpublished mock tbml',
cron: updateUnpublishedMockCron,
callback: () => runOnMasterOnly(updateUnpublishedMockTbml),
name: 'Delete expired event logs for queries',
cron: deleteExpiredEventLogCron,
callback: () => {
libScheduleTestLog('deleteExpireCronTest', deleteExpiredEventLogCron)
deleteExpiredEventLogsForQueries()
},
context: cronContext,
})
}
libScheduleTest(
{ name: 'deleteExpireCronTest', cron: '20 15 * * *', timeZone: 'Europe/Oslo' },
deleteExpiredEventLogCron
)

// push news to rss feed
const pushRssNewsCron: string =
app.config && app.config['ssb.cron.pushRssNews'] ? app.config['ssb.cron.pushRssNews'] : '02 06 * * *'
schedule({
name: 'Push RSS news',
cron: pushRssNewsCron,
callback: () => {
libScheduleTestLog('pushRssNewsCronTest', pushRssNewsCron)
runOnMasterOnly(pushRssNewsJob)
},
context: cronContext,
})
libScheduleTest({ name: 'pushRssNewsCronTest', cron: '01 08 * * *', timeZone: 'Europe/Oslo' }, pushRssNewsCron)
if (app.config && app.config['ssb.mock.enable'] === 'true') {
const updateUnpublishedMockCron: string =
app.config && app.config['ssb.cron.updateUnpublishedMock']
? app.config['ssb.cron.updateUnpublishedMock']
: '0 04 * * *'
schedule({
name: 'Update unpublished mock tbml',
cron: updateUnpublishedMockCron,
callback: () => updateUnpublishedMockTbml(),
context: cronContext,
})
}

// clear specific cache once an hour
const clearCacheCron: string =
app.config && app.config['ssb.cron.clearCacheCron'] ? app.config['ssb.cron.clearCacheCron'] : '01 * * * *'
schedule({
name: 'clear cache',
cron: clearCacheCron,
callback: () => {
clearPartFromPartCache('kpiCalculator')
clearPartFromPartCache('pifCalculator')
clearPartFromPartCache('bkibolCalculator')
clearPartFromPartCache('husleieCalculator')
clearPartFromPartCache('omStatistikken')
clearPartFromPartCache('releasedStatistics')
clearPartFromPartCache('upcomingReleases')
clearPartFromPartCache('articleList')
clearPartFromPartCache('relatedFactPage')
clearPartFromPartCache('archiveAllPublications-nb')
clearPartFromPartCache('archiveAllPublications-en')
},
context: cronContext,
})
// push news to rss feed
const pushRssNewsCron: string =
app.config && app.config['ssb.cron.pushRssNews'] ? app.config['ssb.cron.pushRssNews'] : '02 06 * * *'
schedule({
name: 'Push RSS news',
cron: pushRssNewsCron,
callback: () => {
libScheduleTestLog('pushRssNewsCronTest', pushRssNewsCron)
pushRssNewsJob()
},
context: cronContext,
})
libScheduleTest({ name: 'pushRssNewsCronTest', cron: '01 08 * * *', timeZone: 'Europe/Oslo' }, pushRssNewsCron)

// Update SDDS tables
const updateSDDSTablesCron: string =
app.config && app.config['ssb.cron.updateSDDSTables'] ? app.config['ssb.cron.updateSDDSTables'] : '01 09 * * *'
schedule({
name: 'Update SDDS tables',
cron: updateSDDSTablesCron,
callback: () => {
libScheduleTestLog('updateSDDSCronTest', updateSDDSTablesCron)
runOnMasterOnly(updateSDDSTables)
},
context: cronContext,
})
libScheduleTest({ name: 'updateSDDSCronTest', cron: '01 09 * * *', timeZone: 'Europe/Oslo' }, updateSDDSTablesCron)
// Update SDDS tables
const updateSDDSTablesCron: string =
app.config && app.config['ssb.cron.updateSDDSTables'] ? app.config['ssb.cron.updateSDDSTables'] : '01 09 * * *'
schedule({
name: 'Update SDDS tables',
cron: updateSDDSTablesCron,
callback: () => {
libScheduleTestLog('updateSDDSCronTest', updateSDDSTablesCron)
updateSDDSTables()
},
context: cronContext,
})
libScheduleTest({ name: 'updateSDDSCronTest', cron: '01 09 * * *', timeZone: 'Europe/Oslo' }, updateSDDSTablesCron)

const datasetPublishCron: string =
app.config && app.config['ssb.cron.publishDataset'] ? app.config['ssb.cron.publishDataset'] : '50 05 * * *'
const datasetPublishCron: string =
app.config && app.config['ssb.cron.publishDataset'] ? app.config['ssb.cron.publishDataset'] : '50 05 * * *'

log.info('Run old datasetPublishCron cron-library')
// publish dataset cron job
schedule({
name: 'Dataset publish',
cron: datasetPublishCron,
callback: () => {
libScheduleTestLog('datasetPublishCronTest', datasetPublishCron)
runOnMasterOnly(publishDataset)
},
context: cronContext,
})
libScheduleTest({ name: 'datasetPublishCronTest', cron: '50 07 * * *', timeZone: 'Europe/Oslo' }, datasetPublishCron)
log.info('Run old datasetPublishCron cron-library')
// publish dataset cron job
schedule({
name: 'Dataset publish',
cron: datasetPublishCron,
callback: () => {
libScheduleTestLog('datasetPublishCronTest', datasetPublishCron)
publishDataset()
},
context: cronContext,
})
libScheduleTest(
{ name: 'datasetPublishCronTest', cron: '50 07 * * *', timeZone: 'Europe/Oslo' },
datasetPublishCron
)

// Task
if (isMaster()) {
const timezone: string =
app.config && app.config['ssb.cron.timezone'] ? app.config['ssb.cron.timezone'] : 'Europe/Oslo'

Expand Down

0 comments on commit b827f95

Please sign in to comment.