-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: the ability to do modify services via running a cron (#219)
- Loading branch information
Showing
8 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import resetDownloadUserDataRequestCron from './crons/reset-download-user-data.cron.js'; | ||
import sendHappyBirthdayEmailCron from './crons/happy-birthday.cron.js'; | ||
|
||
import Logger from '../utils/logger.js'; | ||
import cron from 'node-cron'; | ||
|
||
export default class CronsServices { | ||
static async start() { | ||
try { | ||
Logger.info(`Crons services was started!`); | ||
|
||
// everyday at mid night | ||
cron.schedule('0 0 * * *', resetDownloadUserDataRequestCron).start(); | ||
|
||
// everyday at mid night | ||
cron.schedule('0 0 * * *', sendHappyBirthdayEmailCron).start(); | ||
} catch (e) { | ||
Logger.error(e.message); | ||
Chad.flex(e.message, e); | ||
} | ||
} | ||
} |
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,29 @@ | ||
import Logger from '../../utils/logger.js'; | ||
|
||
import EmailServices from '../../services/email.service.js'; | ||
import * as UsersServices from '../../apps/api/v1/users/users.queries.js'; | ||
|
||
export default async function sendHappyBirthdayEmailCron() { | ||
try { | ||
Logger.info('sendHappyBirthdayEmailCron() cron has started!'); | ||
|
||
const users = await UsersServices.getAllUsersWhoseBirthdayIsToday(); | ||
|
||
await Promise.all( | ||
users.map((user) => { | ||
return EmailServices.send({ | ||
to: user.email, | ||
subject: 'Happy Birthday', | ||
template: 'happy-birthday', | ||
data: { | ||
username: user.username, | ||
}, | ||
}); | ||
}), | ||
); | ||
|
||
Logger.info('sendHappyBirthdayEmailCron() cron has finished!'); | ||
} catch (e) { | ||
Logger.error(e.message); | ||
} | ||
} |
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,14 @@ | ||
import Logger from '../../utils/logger.js'; | ||
import * as CachesQueries from '../../apps/api/v1/cache/cache.queries.js'; | ||
|
||
export default async function resetDownloadUserDataRequestCron() { | ||
try { | ||
Logger.info('resetDownloadUserDataRequestCron() cron has started!'); | ||
|
||
await CachesQueries.clearDownloadUserDataRequestCounts(); | ||
|
||
Logger.info('resetDownloadUserDataRequestCron() cron has finished!'); | ||
} catch (e) { | ||
Logger.error(e.message); | ||
} | ||
} |
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