Last active
December 8, 2016 16:36
-
-
Save evantahler/b2f6e90e800916d3d26d to your computer and use it in GitHub Desktop.
ActionHero Example Task: Ping Socket Clients
This file contains 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
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