Skip to content

Commit

Permalink
Forgot this logic needed to be in a function and adds comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scourgemancer authored and nicholastmosher committed Feb 19, 2020
1 parent 64f3a4b commit fde61c6
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/utils/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,13 @@ export const ingestData = (raw: UnstructuredText): StructuredData | null => {
return {genes, annotations, raw};
};


const { geneMap, annotations, groupedAnnotations } = readData();
let mostRecentGeneMap = geneMap;
let mostRecentAnnotations = annotations;
let mostRecentGroupedAnnotations = groupedAnnotations;

const updateData = () => {
export const updateData = () => {
const { execSync } = require("child_process");
const stdout = execSync("wget http://current.geneontology.org/annotations/tair.gaf.gz ; gunzip tair.gaf.gz");

Expand All @@ -478,22 +479,27 @@ const updateData = () => {
mostRecentGroupedAnnotations = groupedAnnotations;
};

let nextDate = new Date();
if (nextDate.getMinutes() === 0 && nextDate.getSeconds() === 0) {
let interval = process.env["UPDATE_INTERVAL"];
if (interval) {
const runningInterval = setInterval(updateData, parseInt(interval));
export const startPeriodicUpdates = () => {
let nextDate = new Date();
// Calls updateData daily, by default, if its the first minute of the day
if (nextDate.getMinutes() === 0) {
let interval = process.env["UPDATE_INTERVAL"];
if (interval) {
const runningInterval = setInterval(updateData, parseInt(interval));
} else {
const runningInterval = setInterval(updateData, (1000 * 60 * 60 * 24)); // Default interval is one day in ms
}
} else {
const runningInterval = setInterval(updateData, (1000 * 60 * 60 * 24));
// Otherwise wait until the start of the next day to begin the periodic updates
nextDate.setDate(nextDate.getDate() + 1);
nextDate.setHours(0);
nextDate.setMinutes(0);
nextDate.setSeconds(0);
let difference = nextDate.getTime() - new Date().getTime();
setTimeout(startPeriodicUpdates, difference);
}
} else {
nextDate.setDate(nextDate.getDate() + 1);
nextDate.setHours(0);
nextDate.setMinutes(0);
nextDate.setSeconds(0);
let difference = nextDate.getTime() - new Date().getTime();
setTimeout(updateData, difference);
}
};
startPeriodicUpdates();

export const getGeneMap = (): GeneMap => { return mostRecentGeneMap; };

Expand Down

0 comments on commit fde61c6

Please sign in to comment.