diff --git a/config/default.js b/config/default.js index 6ec960f..7c08768 100644 --- a/config/default.js +++ b/config/default.js @@ -17,6 +17,7 @@ if (process.env.NODE_ENV === "production") { export default { latestEntriesCount: 10, slackWebhookUrl: process.env.SLACK_WEBHOOK_URL, + slackCron: process.env.SLACK_CRON || "*/10 * * * *", redis: { host: process.env.REDIS_HOST || "localhost", }, diff --git a/src/app.js b/src/app.js index fbfafb7..968af55 100644 --- a/src/app.js +++ b/src/app.js @@ -9,6 +9,7 @@ import routes from "./routes.js"; import logger from "./logger.js"; import NameRecordRepository from "./nameRecordRepository.js"; import fetchAndSendLatestEntries from "./slackNotifier.js"; +import config from "../config/index.js"; const redisClient = await getRedisClient(); const nameRecordRepository = new NameRecordRepository(redisClient); @@ -50,7 +51,7 @@ app.use((err, req, res, next) => { res.status(status).json({ error: message }); }); -cron.schedule("*/1 * * * *", async () => { +cron.schedule(config.slackCron, async () => { logger.info("Checking for new entries to send to Slack..."); await fetchAndSendLatestEntries(nameRecordRepository); }); diff --git a/src/slackNotifier.js b/src/slackNotifier.js index c0d132c..4bcf6c7 100644 --- a/src/slackNotifier.js +++ b/src/slackNotifier.js @@ -33,6 +33,7 @@ export default async function fetchAndSendLatestEntries(repo) { .join("\n"); await sendSlackMessage(`Latest ${latestEntries.length} entries:\n${message}`); + logger.info("Sent latest entries to Slack."); await repo.setLastSentEntryTimestamp( new Date(latestEntries[0].updatedAt).getTime() );