Skip to content

Commit

Permalink
Fix a bug where sendNotifications could crash and prevent precompress…
Browse files Browse the repository at this point in the history
…ion from occuring. Also added try catch into sendNotifications to try and prevent crashes
  • Loading branch information
ecc521 committed Jun 9, 2020
1 parent 79595d1 commit 0a541f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
57 changes: 31 additions & 26 deletions server/sendnotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,42 @@ function sendNotifications(ignoreNoneUntil = false) {
}

for (let prop in rivers) {
let river = rivers[prop]

let flow;
for (let i=readings.length - 1;i>=0;i--) {
//Find the latest non-forecast flow value.
if (readings[i].forecast !== true) {
flow = readings[i];
break;
try {
let river = rivers[prop]

let flow;
for (let i=readings.length - 1;i>=0;i--) {
//Find the latest non-forecast flow value.
if (readings[i].forecast !== true) {
flow = readings[i];
break;
}
}
}

let units = river.units
let units = river.units

let meterInFeet = 3.2808399
let cubicMeterInFeet = meterInFeet**3
let meterInFeet = 3.2808399
let cubicMeterInFeet = meterInFeet**3

if (river.units === "cms") {river.current = flow.cfs / cubicMeterInFeet}
if (river.units === "meters") {river.current = flow.feet / meterInFeet}
else {river.current = flow[units]}
if (river.units === "cms") {river.current = flow.cfs / cubicMeterInFeet}
if (river.units === "meters") {river.current = flow.feet / meterInFeet}
else {river.current = flow[units]}

//Don't delete for email notifications
if (!(river.minimum < river.current && river.current < river.maximum)) {
if (user.type === "email") {
rivers[prop].running = false //For email only, add the river even if it is not running.
data[prop] = rivers[prop]
}
}
else {
data[prop] = rivers[prop] //Add the river if it is running
data[prop].running = true
}
//Don't delete for email notifications
if (!(river.minimum < river.current && river.current < river.maximum)) {
if (user.type === "email") {
rivers[prop].running = false //For email only, add the river even if it is not running.
data[prop] = rivers[prop]
}
}
else {
data[prop] = rivers[prop] //Add the river if it is running
data[prop].running = true
}
}
catch(e) {
console.error(e)
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion server/usgscache.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ async function updateCachedData() {
process.exit()
}

sendNotifications()
try {
sendNotifications()
}
catch (e) {
console.log("ERROR: sendNotifications errored")
console.log(error)
}

console.log("Precompressing files...")
compressor.compressFiles(utils.getSiteRoot())
Expand Down

0 comments on commit 0a541f2

Please sign in to comment.