Skip to content

Instantly share code, notes, and snippets.

@srcoley
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srcoley/acd7b7faaf92b540b962 to your computer and use it in GitHub Desktop.
Save srcoley/acd7b7faaf92b540b962 to your computer and use it in GitHub Desktop.
Resque Notifications
(function(){
var failedCount = null;
var checkFailedInterval;
function getNotificationPrivileges(){
if (Notification.permission !== "granted")
Notification.requestPermission();
}
function checkFailedCount(){
var failedTd = $('td.queue.failed');
var newFailedCount = parseInt(failedTd.next().text());
if( failedCount === null ) {
failedCount = newFailedCount;
} else if ( newFailedCount > failedCount ) {
failedCount = newFailedCount;
notifyFailed(newFailedCount, failedTd);
} else if ( newFailedCount < failedCount) {
failedCount = newFailedCount;
}
}
function notifyFailed(newFailedCount, failedTd) {
var failedLink = failedTd.find('a').attr('href');
var notification = new Notification('Resque Job Failed', {
icon: 'https://pbs.twimg.com/profile_images/456473652515463169/xXR95uqW_normal.png',
body: "A Resque Job has failed. Count: " + newFailedCount
});
clearInterval(checkFailedInterval);
startInterval();
notification.onclick = function(){
window.open(failedLink);
}
}
function startInterval(){
checkFailedInterval = setInterval(checkFailedCount, 2000);
}
function startMonitoring(){
getNotificationPrivileges();
startInterval();
}
startMonitoring();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment