Skip to content

Instantly share code, notes, and snippets.

@evantahler
Last active December 8, 2016 16:36
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 evantahler/b2f6e90e800916d3d26d to your computer and use it in GitHub Desktop.
Save evantahler/b2f6e90e800916d3d26d to your computer and use it in GitHub Desktop.
ActionHero Example Task: Ping Socket Clients
exports.task = {
name: 'pingSocketClients',
description: 'I will send a message to all connected socket clients. This will help with TCP keep-alive and send the current server time. Note that this will only ping the clients of one server, and will not work in cluster',
frequency: 5 * 1000,
queue: 'default',
plugins: [],
pluginOptions: {},
run: function(api, params, next){
for(var i in api.connections.connections){
var connection = api.connections.connections[i];
if(connection.type == 'socket'){
var message = {};
message.context = "api";
message.status = "keep-alive";
message.serverTime = new Date();
connection.sendMessage(message)
}
}
next();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment