Skip to content

Commit

Permalink
Set cron from env
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Feb 22, 2024
1 parent 54791fd commit 1bfcc88
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down
1 change: 1 addition & 0 deletions src/slackNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down

0 comments on commit 1bfcc88

Please sign in to comment.