Skip to content

Commit

Permalink
fix: reset audit table task
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed May 29, 2024
1 parent 75f05ef commit 10285f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import syncRegistries from './sync-registries';
import syncOrganizationMeta from './sync-organization-meta';
import syncGovernanceBody from './sync-governance-body';
import mirrorCheck from './mirror-check';
import resetAuditTable from './reset-audit-table';

const scheduler = new ToadScheduler();

Expand All @@ -25,6 +26,7 @@ const start = () => {
syncRegistries,
syncOrganizationMeta,
mirrorCheck,
resetAuditTable,
];
defaultJobs.forEach((defaultJob) => {
jobRegistry[defaultJob.id] = defaultJob;
Expand Down
28 changes: 22 additions & 6 deletions src/tasks/reset-audit-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@ const task = new Task('reset-audit-table', async () => {
attributes: ['metaValue'],
});

console.log(taskHasRun);

if (taskHasRun === 'true') {
return;
}

logger.info('performing audit table reset');

const where = { type: 'NO CHANGE' };
const noChangeEntries = Audit.findAll({ where });
const noChangeEntries = await Audit.findAll({ where });

if (noChangeEntries) {
return;
if (noChangeEntries.length) {
const result = await Audit.resetToTimestamp('1715385600000'); // ms timestamp for 5/11/2024
logger.info(
'audit table has been reset, records modified: ' + String(result),
);
}

await Audit.resetToTimestamp('1715385600000'); // ms timestamp for 5/11/2024
if (taskHasRun === null) {
await Meta.create({
metaKey: 'may2024AuditResetTaskHasRun',
metaValue: 'true',
});
} else {
await Meta.update(
{ metavalue: 'true' },
{
where: {
metakey: 'may2024AuditResetTaskHasRun',
},
returning: true,
},
);
}
} catch (error) {
logger.error(
`Retrying in ${
Expand Down

0 comments on commit 10285f2

Please sign in to comment.