<commit_before>var dashboard = require('./dashboard');
var log = require('./log').logger('debug');
var config = require('./config');
var path = require('path');
var pathIsInside = require('path-is-inside');

var watch_semaphore = 0;
var NCP_TIMEOUT = 4000;

var appReloader = function(event, pth, details) {
  // Don't watch for changes if there is an update in progress
  if(watch_semaphore) { return; }
 
  var pth = details.watchedPath || details.path;

  // Determine which app changed, and re-copy that app
  app_index = dashboard.getAppIndex();
  for(var app_id in app_index) {
    app_path = app_index[app_id].app_archive_path;
    if(pathIsInside(app_path, pth) || pathIsInside(pth, app_path)) {
      log.info(app_id + ' was changed. Reloading...');
      watch_semaphore+=1;
      var timeout = setTimeout(function() {
        log.warn('Timeout waiting for reload of ' + app_id);
        watch_semaphore-=1;
      }, NCP_TIMEOUT);
      return dashboard.reloadApp(app_id, function(err, result) {
        clearTimeout(timeout);
        log.info(app_id + ' updated.');
        watch_semaphore-=1;  
      });        
    }
  } 
}; 

function startDebug() {
  log.info("Starting debug watcher...");
  var chokidar = require('chokidar');
  var watcher = chokidar.watch('./dashboard/apps', {
    ignored: /[\/\\]\./,
    persistent: true
  });
  watcher.on('raw', appReloader);

  var watcher = chokidar.watch(config.getDataDir('apps'), {
    ignored: /[\/\\]\./,
    persistent: true
  });
  watcher.on('raw', appReloader);

}

exports.start = startDebug;<commit_msg>Further improvements to app debug mode<commit_after>var dashboard = require('./dashboard');
var log = require('./log').logger('debug');
var config = require('./config');
var path = require('path');
var pathIsInside = require('path-is-inside');

var watch_semaphore = 0;
var NCP_TIMEOUT = 4000;

var appReloader = function(event, pth, details) {
 
  var pth = details.watchedPath || details.path;

  // Don't watch for changes if there is an update in progress
  if(watch_semaphore) { 
    log.warn("Not reloading " + pth + " because a reload is already in progress.");
    return; 
  }

  // Determine which app changed, and re-copy that app
  app_index = dashboard.getAppIndex();
  for(var app_id in app_index) {
    app_path = app_index[app_id].app_archive_path;
    if(pathIsInside(app_path, pth) || pathIsInside(pth, app_path)) {
      log.info(app_id + ' was changed. Reloading...');
      watch_semaphore+=1;
      var timeout = setTimeout(function() {
        log.warn('Timeout waiting for reload of ' + app_id);
        watch_semaphore-=1;
        watch_semaphore = watch_semaphore < 0 ? 0 : watch_semaphore;
      }, NCP_TIMEOUT);
      return dashboard.reloadApp(app_id, function(err, result) {
        clearTimeout(timeout);
        log.info(app_id + ' updated.');
        watch_semaphore-=1;  
        watch_semaphore = watch_semaphore < 0 ? 0 : watch_semaphore;
      });        
    }
  } 
}; 

function startDebug() {
  log.info("Starting debug watcher...");
  var chokidar = require('chokidar');
  var watcher = chokidar.watch('./dashboard/apps', {
    ignored: /[\/\\]\./,
    persistent: true
  });
  watcher.on('raw', appReloader);

  var watcher = chokidar.watch(config.getDataDir('apps'), {
    ignored: /[\/\\]\./,
    persistent: true
  });
  watcher.on('raw', appReloader);

}

exports.start = startDebug;
{'fraction_non_alphanumeric': 0.15138154027042916, 'fraction_numerical': 0.005878894767783657, 'mean_word_length': 3.1960542540073984, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6751416', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1153, 'n_words': 250}