<commit_before>'use strict';

const cluster = require('cluster');
const Backendless = require('backendless');
const logger = require('../../util/logger');
const MessagesBroker = require('../services/messages-broker');
const tasksExecutor = require('./tasks/executor');
const consoleLogger = require('../../util/console-logger');

const DRIVER_TASKS_CHANNEL = 'CODE_RUNNER_DRIVER';

const flushPendingLogs = () => {
  if (Backendless.applicationId) {
    return Backendless.Logging.flush().catch(err => {
      logger.error('Error during logs flushing', err.message);
    });
  }
};

process.on('uncaughtException', function(err) {
  logger.error('Unhandled exception! ' + err.message + '/n' + err.stack);
  process.exit(1);
});

const startMaster = opts => {
  const numCPUs = require('os').cpus().length;
  const workersCount = opts.workers || numCPUs;

  logger.info(`Starting Pro Code Runner with ${workersCount} workers...`);
  logger.info(`Backendless Repository Path is set to [${opts.backendless.repoPath}]`);

  const startWorker = () => {
    const worker = cluster.fork();
    logger.info(`[${worker.process.pid}] Worker started`);
  };

  for (let i = 0; i < workersCount; i++) {
    startWorker();
  }

  cluster.on('exit', (worker) => {
    logger.info(`[${worker.process.pid}] Worker exited`);

    startWorker();
  });

  logger.info('Ready and waiting for Server Code tasks..');
};

const startWorker = opts => {
  process.title = 'Backendless CodeRunner Helper';

  logger.usePid = true;

  consoleLogger.attach();

  const messageBroker = new MessagesBroker(opts.backendless.msgBroker);
  messageBroker.on('error', err => {
    logger.error(err);
    process.exit(1);
  });

  const getTask = () => messageBroker.getTask(DRIVER_TASKS_CHANNEL);

  const processTask = task => {
    function sendResult(result) {
      logger.info('Processing finished');<commit_msg>pro worker process name change<commit_after>'use strict';

const cluster = require('cluster');
const Backendless = require('backendless');
const logger = require('../../util/logger');
const MessagesBroker = require('../services/messages-broker');
const tasksExecutor = require('./tasks/executor');
const consoleLogger = require('../../util/console-logger');

const DRIVER_TASKS_CHANNEL = 'CODE_RUNNER_DRIVER';

const flushPendingLogs = () => {
  if (Backendless.applicationId) {
    return Backendless.Logging.flush().catch(err => {
      logger.error('Error during logs flushing', err.message);
    });
  }
};

process.on('uncaughtException', function(err) {
  logger.error('Unhandled exception! ' + err.message + '/n' + err.stack);
  process.exit(1);
});

const startMaster = opts => {
  const numCPUs = require('os').cpus().length;
  const workersCount = opts.workers || numCPUs;

  logger.info(`Starting Pro Code Runner with ${workersCount} workers...`);
  logger.info(`Backendless Repository Path is set to [${opts.backendless.repoPath}]`);

  const startWorker = () => {
    const worker = cluster.fork();
    logger.info(`[${worker.process.pid}] Worker started`);
  };

  for (let i = 0; i < workersCount; i++) {
    startWorker();
  }

  cluster.on('exit', (worker) => {
    logger.info(`[${worker.process.pid}] Worker exited`);

    startWorker();
  });

  logger.info('Ready and waiting for Server Code tasks..');
};

const startWorker = opts => {
  process.title = 'Backendless CodeRunner Helper for JS';

  logger.usePid = true;

  consoleLogger.attach();

  const messageBroker = new MessagesBroker(opts.backendless.msgBroker);
  messageBroker.on('error', err => {
    logger.error(err);
    process.exit(1);
  });

  const getTask = () => messageBroker.getTask(DRIVER_TASKS_CHANNEL);

  const processTask = task => {
    function sendResult(result) {
      logger.info('Processing finished');
{'fraction_non_alphanumeric': 0.16737064413938754, 'fraction_numerical': 0.0015839493136219642, 'mean_word_length': 4.183310533515732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6790487', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1156, 'n_words': 251}