-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GEO-1007 Schedule to delete announcements (#820)
- Loading branch information
Showing
17 changed files
with
480 additions
and
18 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
# Matched against repo root (asterisk) | ||
* @sukanya-rath | ||
|
||
# Matched against directories | ||
# /.github/workflows/ @sukanya-rath | ||
* @bcgov/FIN_IMB_AMD | ||
|
||
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners |
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
44 changes: 44 additions & 0 deletions
44
backend/src/schedulers/delete-announcements-scheduler.spec.ts
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,44 @@ | ||
import waitFor from 'wait-for-expect'; | ||
import deleteAnnouncementsJob from './delete-announcements-scheduler'; | ||
import { announcementService } from '../v1/services/announcements-service'; | ||
|
||
jest.mock('../config', () => ({ | ||
config: { | ||
get: (key: string) => { | ||
const settings = { | ||
'server:deleteAnnouncementsCronTime': '121212121', | ||
}; | ||
|
||
return settings[key]; | ||
}, | ||
}, | ||
})); | ||
|
||
jest.mock('./create-job', () => ({ | ||
createJob: jest.fn((cronTime, callback, mutex, { title, message }) => { | ||
return { | ||
start: jest.fn(async () => { | ||
console.log(`Mock run`); | ||
try { | ||
await callback(); // Simulate the callback execution | ||
} catch (e) { | ||
console.error(`Mock error`); | ||
} finally { | ||
console.log(`Mock end run`); | ||
} | ||
}), | ||
}; | ||
}), | ||
})); | ||
jest.mock('../v1/services/announcements-service'); | ||
|
||
describe('delete-announcements-scheduler', () => { | ||
it('should run the function', async () => { | ||
deleteAnnouncementsJob.start(); | ||
await waitFor(async () => { | ||
expect( | ||
announcementService.deleteAnnouncementsSchedule, | ||
).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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,25 @@ | ||
import { config } from '../config'; | ||
import { logger as log } from '../logger'; | ||
import advisoryLock from 'advisory-lock'; | ||
import { createJob } from './create-job'; | ||
import { announcementService } from '../v1/services/announcements-service'; | ||
|
||
const SCHEDULER_NAME = 'DeleteAnnouncements'; | ||
const mutex = advisoryLock(config.get('server:databaseUrl'))( | ||
`${SCHEDULER_NAME}-lock`, | ||
); | ||
const crontime = config.get('server:deleteAnnouncementsCronTime'); | ||
|
||
export default createJob( | ||
crontime, | ||
async () => { | ||
log.info(`Starting scheduled job '${SCHEDULER_NAME}'.`); | ||
await announcementService.deleteAnnouncementsSchedule(); | ||
log.info(`Completed scheduled job '${SCHEDULER_NAME}'.`); | ||
}, | ||
mutex, | ||
{ | ||
title: `Error in ${SCHEDULER_NAME}`, | ||
message: `Error in scheduled job: ${SCHEDULER_NAME}`, | ||
}, | ||
); |
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
Oops, something went wrong.