mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 11:07:43 +00:00
feat: add redis (#1390)
This commit is contained in:
@@ -14,6 +14,7 @@ import {sendTelegramMessage} from './telegram';
|
||||
import {sendTweet} from './twitter';
|
||||
import {sendTwilioMessage} from './twilio';
|
||||
import {sendTwitchMessage} from './twitch';
|
||||
import updateRedis from './redis';
|
||||
|
||||
export function sendNotification(link: Link, store: Store) {
|
||||
// Priority
|
||||
@@ -33,4 +34,5 @@ export function sendNotification(link: Link, store: Store) {
|
||||
sendTweet(link, store);
|
||||
sendTwilioMessage(link, store);
|
||||
sendTwitchMessage(link, store);
|
||||
updateRedis(link, store);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {Link, Store} from '../store/model';
|
||||
import {config} from '../config';
|
||||
import {logger} from '../logger';
|
||||
import redis from 'redis';
|
||||
|
||||
const {url} = config.notifications.redis;
|
||||
|
||||
const client = redis.createClient({
|
||||
url
|
||||
});
|
||||
|
||||
const updateRedis = (link: Link, store: Store) => {
|
||||
try {
|
||||
if (url) {
|
||||
const key = `${store.name}:${link.brand}:${link.model}`
|
||||
.split(' ')
|
||||
.join('-');
|
||||
|
||||
const value = {
|
||||
...link,
|
||||
labels: store.labels,
|
||||
links: store.links,
|
||||
name: store.name,
|
||||
updatedAt: new Date().toUTCString()
|
||||
};
|
||||
|
||||
const redisUpdated = client.set(key, JSON.stringify(value));
|
||||
|
||||
if (redisUpdated) {
|
||||
logger.info('✔ redis updated');
|
||||
} else {
|
||||
logger.error(`✖ couldn't update redis for key (${key})`);
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error("✖ couldn't update redis", error);
|
||||
}
|
||||
};
|
||||
|
||||
export default updateRedis;
|
||||
Reference in New Issue
Block a user