Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send error notification to slack #108

Merged
merged 7 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/lib/slack/errorNotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const slackapi = require("~slack/webApi");
const { TECH_CHANNEL } = require("~slack/constants");
const { findChannelByName } = require("~slack/channels");

const sentErrors = [];

module.exports = async function sendErrorNotification(error) {
/**
*
*/
const now = new Date();

const twoHoursAgo = new Date(now.getTime() - 120 * 60000);

let shouldSend = true;

for (const sentError of sentErrors) {
// dont send if error occured within last 2 hours
if (
sentError[0] === error.message &&
sentError[1].getTime() > twoHoursAgo.getTime()
) {
shouldSend = false;
}
}

if (shouldSend) {
let errText = `${error.stack}`;
errText = `<!here|here> - We've got an error!\n\`\`\`${errText}\`\`\``;

const wgTechChannel = await findChannelByName(TECH_CHANNEL);
await slackapi.chat.postMessage({
channel: wgTechChannel.id,
text: errText,
});

sentErrors.push([error.message, now]);
}
};
2 changes: 1 addition & 1 deletion src/lib/strings/locales/en/slackapp.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"intakeVolunteers": "intake_volunteers",
"deliveryVolunteers": "delivery_volunteers",
"flyering": "flyer_squad",
"tech": "tech",
"tech": "wg_tech",
"communityReimbursements": "community_reimbursement",
"hatHolders": "hat_holders"
},
Expand Down
11 changes: 9 additions & 2 deletions src/workers/airtable-sync/paymentWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ const {
paymentRequestsFields,
paymentRequestsSensitiveFields,
} = require("~airtable/tables/paymentRequests");
const sendErrorNotification = require("~slack/errorNotification");
const newExternalDonorPayment = require("./actions/payments/newExternalDonorPayment");
const newPaymentRequest = require("./actions/payments/newPaymentRequest");
const updateReimbursementMessage = require("./actions/payments/updateReimbursementStatus");

const defaultInterval = 10000;

const errFunc = async (error) => {
sendErrorNotification(error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: can you make the function async and await the sendError? functionally the same, but a bit more resistant to a potential weird future change-detector update

};

function startWorker(interval) {
let pollInterval = interval;
if (pollInterval < defaultInterval) {
Expand Down Expand Up @@ -50,7 +55,8 @@ function startWorker(interval) {
}
});
return Promise.all(promises);
}
},
errFunc
);

const donorSignupChanges = new ChangeDetector(donorPaymentsTable, {
Expand Down Expand Up @@ -82,7 +88,8 @@ function startWorker(interval) {
}
});
return Promise.all(promises);
}
},
errFunc
);
}

Expand Down
8 changes: 7 additions & 1 deletion src/workers/airtable-sync/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ const {
fields: requestFields,
SENSITIVE_FIELDS: sensitiveRequestFields,
} = require("~airtable/tables/requests");
const sendErrorNotification = require("~slack/errorNotification");
const updateMessageContent = require("./actions/updateMessageContent");
const notifyManyc = require("./actions/notifyManyc");

const defaultInterval = 10000;

const errFunc = async (error) => {
await sendErrorNotification(error);
};

function startWorker(interval) {
let pollInterval = interval;
if (pollInterval < defaultInterval) {
Expand Down Expand Up @@ -57,7 +62,8 @@ function startWorker(interval) {
}
});
return Promise.all(promises);
}
},
errFunc
);
}

Expand Down