Skip to content

Instantly share code, notes, and snippets.

@rivancic
Last active September 18, 2017 07:33
Show Gist options
  • Save rivancic/b2a8706882b1d53c2de3be744635e779 to your computer and use it in GitHub Desktop.
Save rivancic/b2a8706882b1d53c2de3be744635e779 to your computer and use it in GitHub Desktop.
monitoring script - mark outdated jobs
/**
* This script is used on monitoring page to mark the job id which is older that one day.
*/
$(document).ready(function() { markOld();});
function markOld() {
console.log("Start listening on changes");
$(".container h1:first").css("color","red");
$(document).on("DOMSubtreeModified", ".container h1:first", function () {
console.log("items changed");
markSingleLine();
});
}
function markSingleLine() {
var $table = $(".container table:first");
console.log("=========================");
// Get current time stamp
var d = new Date();
var currentMilliseconds = d.getTime();
$table.find("tr").each(function() {
console.log("tr found");
// Get id column
var $idRow = $(this).find("td:nth-child(3)");
var $ttId = $idRow.first("tt");
console.log("ID: "+ $ttId.text());
// Get date column
var $dateRow = $(this).find("td:nth-child(4)");
var $dateTt = $dateRow.first("tt");
var timeStringRepresentation = $dateTt.text();
console.log("Date: "+ $dateTt.text());
// Get column time
var timeInMilis = Date.parse(timeStringRepresentation);
console.log("Time in miliseconds: "+ timeInMilis);
// Get time difference
var timeDiff = Math.abs(timeInMilis - currentMilliseconds);
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log("Diff in days: " + diffDays);
// Mark if time difference is more than 1 day
if(diffDays > 1) {
$ttId.css("color","red");
}
});
console.log("=========================");
}
@rivancic
Copy link
Author

This script is used on monitoring page to mark the job id which is older that one day.

Values are read from the table. In 3rd row there is id of the job and in 4th row there is start date of the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment