Last active
August 29, 2015 14:20
-
-
Save srcoley/acd7b7faaf92b540b962 to your computer and use it in GitHub Desktop.
Resque Notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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