-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1101 from Chia-Network/reset-audit-table-to-gener…
…ation feat: added resetToGeneration audit endpoint
- Loading branch information
Showing
7 changed files
with
221 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { SimpleIntervalJob, Task } from 'toad-scheduler'; | ||
import { Audit, Meta } from '../models'; | ||
import { logger } from '../config/logger.cjs'; | ||
import dotenv from 'dotenv'; | ||
import _ from 'lodash'; | ||
dotenv.config(); | ||
|
||
const task = new Task('reset-audit-table', async () => { | ||
try { | ||
const metaResult = await Meta.findOne({ | ||
where: { | ||
metaKey: 'may2024AuditResetTaskHasRun', | ||
}, | ||
attributes: ['metaValue'], | ||
raw: true, | ||
}); | ||
|
||
const taskHasRun = metaResult?.metaValue; | ||
|
||
if (taskHasRun === 'true') { | ||
return; | ||
} | ||
|
||
logger.info('performing audit table reset'); | ||
|
||
const where = { type: 'NO CHANGE' }; | ||
const noChangeEntries = await Audit.findAll({ where }); | ||
|
||
if (noChangeEntries.length) { | ||
const result = await Audit.resetToDate('2024-05-11'); | ||
logger.info( | ||
'audit table has been reset, records modified: ' + String(result), | ||
); | ||
} | ||
|
||
if (_.isNil(taskHasRun)) { | ||
await Meta.create({ | ||
metaKey: 'may2024AuditResetTaskHasRun', | ||
metaValue: 'true', | ||
}); | ||
} else { | ||
await Meta.update( | ||
{ metavalue: 'true' }, | ||
{ | ||
where: { | ||
metakey: 'may2024AuditResetTaskHasRun', | ||
}, | ||
returning: true, | ||
}, | ||
); | ||
} | ||
} catch (error) { | ||
logger.error('Retrying in 600 seconds', error); | ||
} | ||
}); | ||
|
||
const job = new SimpleIntervalJob( | ||
{ | ||
seconds: 600, | ||
runImmediately: true, | ||
}, | ||
task, | ||
{ id: 'reset-audit-table', preventOverrun: true }, | ||
); | ||
|
||
export default job; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters