-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fde61c6
commit f2a9bbe
Showing
3 changed files
with
54 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { app } from './server'; | ||
import { updateData, startPeriodicUpdates } from './utils/data_fetcher'; | ||
|
||
updateData(); | ||
const default_interval: string = (1000 * 60 * 60 * 24).toString(); | ||
const interval: string = process.env["UPDATE_INTERVAL"] || default_interval; | ||
startPeriodicUpdates(parseInt(interval)); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
app.listen(PORT, () => { | ||
console.log(`🚢 Now listening on 0.0.0.0:${PORT} 🔥`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {GeneMap, IAnnotation, GroupedAnnotations, IGene, readData} from "./ingest"; | ||
|
||
let mostRecentGeneMap: GeneMap; | ||
let mostRecentAnnotations: IAnnotation[]; | ||
let mostRecentGroupedAnnotations: GroupedAnnotations<Set<IGene>>; | ||
|
||
export 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; | ||
}; | ||
|
||
export const startPeriodicUpdates = (interval: number = (1000 * 60 * 60 * 24), startDate: Date = getTomorrowMorning()) => { | ||
const now = new Date(); | ||
if (sameTimeOfDay(startDate, now)) { | ||
setInterval(updateData, interval); | ||
} else { | ||
let difference = startDate.getTime() - now.getTime(); | ||
if (difference > 0) { | ||
setTimeout(startPeriodicUpdates, difference, interval, startDate); | ||
} | ||
setInterval(updateData, interval); // Just begins the updates now if the startDate is in the past | ||
} | ||
}; | ||
|
||
const getTomorrowMorning = (): Date => { | ||
const tomorrowMorning: Date = new Date(); | ||
tomorrowMorning.setDate(tomorrowMorning.getDate() + 1); | ||
tomorrowMorning.setHours(0); | ||
tomorrowMorning.setMinutes(0); | ||
tomorrowMorning.setSeconds(0); | ||
return tomorrowMorning; | ||
}; | ||
|
||
const sameTimeOfDay = (time1, time2) => { | ||
return time1.getHours() === time2.getHours() && time1.getMinutes() === time2.getMinutes(); | ||
} | ||
|
||
export const getGeneMap = (): GeneMap => { return mostRecentGeneMap; }; | ||
|
||
export const getAnnotations = (): IAnnotation[] => { return mostRecentAnnotations; }; | ||
|
||
export const getGroupedAnnotations = (): GroupedAnnotations<Set<IGene>> => { return mostRecentGroupedAnnotations; }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters