Skip to content

Instantly share code, notes, and snippets.

@zackproser
Created July 21, 2015 06:05
Show Gist options
  • Save zackproser/421f3f6866a88f10b976 to your computer and use it in GitHub Desktop.
Save zackproser/421f3f6866a88f10b976 to your computer and use it in GitHub Desktop.
How to look up a child process by a property - and kill it.
/**
* Finds a currently running attack by phone number and terminates it in response to an admin stop attack request
*
* @param {String} requesting_admin - The phone number of the admin requesting a stop
* @param {String} target_number - The phone number that should not be attacked anymore
* @return void
*/
handleAdminStopRequest = function(requesting_admin, target_number) {
var currentAttacks = app.get('activeAttacks');
var foundAttack = false;
if (!currentAttacks.length) return;
currentAttacks.forEach(function(currentAttack){
if (currentAttack.target_number == target_number){
foundAttack = currentAttack;
}
});
if (foundAttack){
foundAttack.kill();
sendResponseSMS(requesting_admin, 'Successfully terminated CatFacts Attack on ' + target_number);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment