Skip to content
Permalink
Browse files

Updates initial logging

  • Loading branch information
davidmerfield committed Nov 24, 2019
1 parent 1149094 commit b2576a149540895192a66dca2c3e8042dad9c0ed
Showing with 27 additions and 18 deletions.
  1. +6 −6 app/brochure/routes/featured/index.js
  2. +5 −2 app/index.js
  3. +16 −10 app/scheduler.js
@@ -8,7 +8,7 @@
var schedule = require("node-schedule").scheduleJob;
var filter = require("./filter");
var config = require("config");

var clfdate = require("helper").clfdate;
var Cache = require("express-disk-cache");
var cache = new Cache(config.cache_directory);

@@ -20,29 +20,29 @@ var featured = require("./featured.json");
// elsewhere. I need to add zero-downtime deploy. Once I do, remove delay.
setTimeout(check, 1000 * 5);

console.log("Featured sites: scheduled check each midnight!");
console.log(clfdate(), "Featured sites: scheduled check each midnight!");
schedule({ hour: 8, minute: 0 }, check);

function check() {
if (config.environment === "development") {
console.log("Featured sites: not checking in development environment");
console.log(clfdate(), "Featured sites: not checking in development environment");
return;
}

console.log("Featured sites: checking which sites point to Blot");
console.log(clfdate(), "Featured sites: checking which sites point to Blot");
filter(featured, function(err, filtered, missing) {
if (err) return console.log(err);

featured = filtered;

missing.forEach(function(site) {
console.log("Featured sites:", site.host, "no longer points to Blot");
console.log(clfdate(), "Featured sites:", site.host, "no longer points to Blot");
});

cache.flush(config.host, function(err) {
if (err) console.log(err);

console.log("Featured sites: check completed!");
console.log(clfdate(), "Featured sites: check completed!");
});
});
}
@@ -1,13 +1,16 @@
console.log(require("helper").clfdate(), "app starting");

var config = require("config");
var Express = require("express");
var helmet = require("helmet");
var vhost = require("vhost");
var clfdate = require("helper").clfdate;
var blog = require("./blog");
var brochure = require("./brochure");
var dashboard = require("./dashboard");
var cdn = require("./cdn");
var scheduler = require("./scheduler");
var clfdate = require("helper").clfdate;


// Welcome to Blot. This is the Express application which listens on port 8080.
// NGINX listens on port 80 in front of Express app and proxies requests to
@@ -98,7 +101,7 @@ Blot.listen(config.port, function() {
// The endpoints test listens for this line in stdout
// so if you change its text, ensure you update the
// START_MESSAGE variable in tests/app/endpoints.js
console.log("Blot is listening on port", config.port);
console.log(clfdate(), "app listening on port", config.port);
});

// Schedule backups, subscription renewal emails
@@ -8,27 +8,31 @@ var backup = require("./backup");
var dailyUpdate = require("./scheduler/daily");
var helper = require("helper");
var email = helper.email;
var clfdate = helper.clfdate;

module.exports = function() {
// Bash the cache for scheduled posts
cacheScheduler(function(stat) {
console.log(stat);
console.log(clfdate(), stat);
});

// Warn users about impending subscriptions
User.getAllIds(function(err, uids) {
async.each(uids, User.scheduleSubscriptionEmail, function(err) {
if (err) {
console.error("Error scheduling subscription emails:", err);
console.error(clfdate(), "Error scheduling subscription emails:", err);
} else {
console.log("Scheduled emails for renewals and expiries!");
console.log(clfdate(), "Scheduled emails for renewals and expiries!");
}
});
});

console.log("Scheduled daily check of storage disk usage for 6am!");
console.log(
clfdate(),
"Scheduled daily check of storage disk usage for 6am!"
);
schedule({ hour: 10, minute: 0 }, function() {
console.log("Scheduler: Checking available disk space");
console.log(clfdate(), "Scheduler: Checking available disk space");

require("child_process").exec("df -h", function(err, stdout) {
if (err) throw err;
@@ -42,6 +46,7 @@ module.exports = function() {

if (parseInt(usage) < 90) {
console.log(
clfdate(),
"Scheduler: Disk usage check passed! Usage:",
usage,
"Space available:",
@@ -51,6 +56,7 @@ module.exports = function() {
}

console.log(
clfdate(),
"Scheduler: Disk usage check failed! Usage:",
usage,
"Space available:",
@@ -67,20 +73,20 @@ module.exports = function() {
});
});

console.log("Scheduled daily backups for 3am!");
console.log(clfdate(), "Scheduled daily backups for 3am!");
schedule({ hour: 11, minute: 0 }, function() {
// Start the backup daemon
console.log("Backup: It is 1am, time to start!");
console.log(clfdate(), "Backup: It is 1am, time to start!");
backup.now();
});

// At some point I should check this doesnt consume too
// much memory
console.log("Scheduled daily update email for 6:05am!");
console.log(clfdate(), "Scheduled daily update email for 6:05am!");
schedule({ hour: 10, minute: 5 }, function() {
console.log("Generating daily update email...");
console.log(clfdate(), "Generating daily update email...");
dailyUpdate(function() {
console.log("Daily update email update was sent.");
console.log(clfdate(), "Daily update email update was sent.");
});
});
};

0 comments on commit b2576a1

Please sign in to comment.
You can’t perform that action at this time.