diff --git a/docker-compose.yml b/docker-compose.yml index 79f8f87..d33c533 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: environment: GENES_FILE: "/ifad/files/gene-types.txt" ANNOTATIONS_FILE: "/ifad/files/tair.gaf" + UPDATE_INTERVAL: 86400000 ports: - 80:3000 volumes: diff --git a/src/utils/ingest.ts b/src/utils/ingest.ts index 251f106..e16e67b 100644 --- a/src/utils/ingest.ts +++ b/src/utils/ingest.ts @@ -462,3 +462,41 @@ export const ingestData = (raw: UnstructuredText): StructuredData | null => { // Return all structured data return {genes, annotations, raw}; }; + +const { geneMap, annotations, groupedAnnotations } = readData(); +let mostRecentGeneMap = geneMap; +let mostRecentAnnotations = annotations; +let mostRecentGroupedAnnotations = groupedAnnotations; + +const updateData = () => { + const { execSync } = require("child_process"); + const stdout = execSync("wget http://current.geneontology.org/annotations/tair.gaf.gz ; gunzip tair.gaf.gz"); + + const { geneMap, annotations, groupedAnnotations } = readData(); + mostRecentGeneMap = geneMap; + mostRecentAnnotations = annotations; + 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)); + } else { + const runningInterval = setInterval(updateData, (1000 * 60 * 60 * 24)); + } +} 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); +} + +export const getGeneMap = (): GeneMap => { return mostRecentGeneMap; }; + +export const getAnnotations = (): IAnnotation[] => { return mostRecentAnnotations; }; + +export const getGroupedAnnotations = (): GroupedAnnotations> => { return mostRecentGroupedAnnotations; };