Permalink
Browse files

Fetch news periodically

  • Loading branch information...
jkelin committed Aug 18, 2018
1 parent 4b2b26b commit c94b098c2b4f73eecec2ea008665f9f191b30298
Showing with 15 additions and 9 deletions.
  1. +9 −2 src/helpers.ts
  2. +6 −7 src/index.ts
View
@@ -10,6 +10,7 @@ import tags from '../data/clan-tags.json';
import { removeDiacritics } from "./removeAccents";
import { Request } from "../node_modules/@types/express-serve-static-core";
import { INews } from "./types";
import { CronJob } from "cron";
export function tryConvertIpv6ToIpv4(ip: string){
var regex = /^::ffff:([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
@@ -23,7 +24,7 @@ export function tryConvertIpv6ToIpv4(ip: string){
}
export function getNews() {
winston.info("Resolving news");
winston.info("Fetching news");
return new Promise<INews[]>(function (resolve, reject) {
var client = github.client();
@@ -58,7 +59,13 @@ export function getNews() {
})
}
export const tribes_news = getNews().catch(() => []);
export let tribes_news: Promise<INews[]>;
new CronJob({
cronTime: '0 0 * * * *',
onTick: () => tribes_news = getNews(),
start: true,
runOnInit: true
});
export function getClientIp(req: Request) {
var ipAddress;
View
@@ -191,12 +191,11 @@ process.on('uncaughtException', (ex) => {
Raven.captureException(ex, () => process.exit(1));
});
new CronJob(
'0 0 0 * * *',
function() {
console.warn('Running CRON')
new CronJob({
cronTime: '0 0 0 * * *',
onTick: () => {
winston.info('Recalculating identities');
exec('yarn script:recalculate_identities')
},
() => {},
true
);
start: true
});

0 comments on commit c94b098

Please sign in to comment.