<commit_before>module.exports.run = function(worker) {
  var scServer = worker.scServer;

  scServer.addMiddleware(scServer.MIDDLEWARE_EMIT, function (socket, channel, data, next) {
    if (channel.substr(0, 3) === 'sc-' || channel === 'respond' || channel === 'log') {
      scServer.exchange.publish(channel, data);
    }
    next();
  });

  scServer.on('connection', function(socket) {
    socket.on('login', function (credentials, respond) {
      var channelName = credentials === 'master' ? 'respond' : 'log';
      worker.exchange.subscribe('sc-' + socket.id).watch(function(msg) {
        socket.emit(channelName, msg);
      });
      respond(null, channelName);
    });
    socket.on('disconnect', function() {
      var channel = worker.exchange.channel('sc-' + socket.id);
      channel.unsubscribe(); channel.destroy();
    });
  });
};
<commit_msg>Notify monitors when an instance is disconnected<commit_after>module.exports.run = function(worker) {
  var scServer = worker.scServer;

  scServer.addMiddleware(scServer.MIDDLEWARE_EMIT, function (socket, channel, data, next) {
    if (channel.substr(0, 3) === 'sc-' || channel === 'respond' || channel === 'log') {
      scServer.exchange.publish(channel, data);
    }
    next();
  });

  scServer.on('connection', function(socket) {
    socket.on('login', function (credentials, respond) {
      var channelName = credentials === 'master' ? 'respond' : 'log';
      worker.exchange.subscribe('sc-' + socket.id).watch(function(msg) {
        socket.emit(channelName, msg);
      });
      respond(null, channelName);
    });
    socket.on('disconnect', function() {
      var channel = worker.exchange.channel('sc-' + socket.id);
      channel.unsubscribe(); channel.destroy();
      scServer.exchange.publish('log', { id: socket.id, type: 'DISCONNECTED' });
    });
  });
};

{'fraction_non_alphanumeric': 0.1780673181324647, 'fraction_numerical': 0.002171552660152009, 'mean_word_length': 3.5732009925558312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676892', 'n_tokens_mistral': 574, 'n_tokens_neox': 555, 'n_words': 107}