<commit_before>/**
 * Mixin for cluster
 * @function clusterMix
 * @param {function} BaseClass - Class to mix
 * @returns {function} Mixed class
 */
'use strict'

const cluster = require('cluster')
const clayResourceName = require('clay-resource-name')

/** @lends clusterMix */
function clusterMix (BaseClass) {
  /** @class ClusterMixed */
  class ClusterMixed extends BaseClass {
    get $$clusterMixed () {
      return true
    }

    constructor () {
      super(...arguments)
      const s = this
      s._clusterWorkerListners = {}
    }

    setupCluster () {
      const s = this
      if (cluster.isMaster) {
        const {workers} = cluster
        for (const id of Object.keys(workers || {})) {
          s.bindClusterWorker(workers[id])
        }
        cluster.setMaxListeners(cluster.getMaxListeners() + 2)
        cluster.addListener('online', (worker) => s.bindClusterWorker(worker))
        cluster.addListener('exit', (worker) => s.unbindClusterWorker(worker))
      } else {
        const {worker} = cluster
        s.bindClusterWorker(worker)
      }
    }

    bindClusterWorker (worker) {
      const s = this
      const resourceName = String(clayResourceName(s))
      const listeners = {
        'message': async ({$$clay, $$from, $$resource, event, data}) => {
          if (!$$clay) {
            return
          }
          if (resourceName !== $$resource) {
            return
          }

          if (/^cly:entity/.test(event)) {
            data = await s.restoreClusterEventData(data)
          }
          for (const listener of s.listeners(event)) {
            listener(data)
          }
          if (cluster.isMaster) {
            const {workers} = cluster
            for (const id of Object.keys(workers)) {
              const worker = workers[id]
              const skip = String(id) === String($$from)
              if (skip) {
                continue
              }
              worker.send({$$clay, $$resource, $$from, event, data})
            }
          }
        }
      }
      s._clusterWorkerListners[worker.id] = listeners
      const events = Object.keys(listeners)
      worker.setMaxListeners(worker.getMaxListeners() + events.length)<commit_msg>bugfix<commit_after>/**
 * Mixin for cluster
 * @function clusterMix
 * @param {function} BaseClass - Class to mix
 * @returns {function} Mixed class
 */
'use strict'

const cluster = require('cluster')
const clayResourceName = require('clay-resource-name')

/** @lends clusterMix */
function clusterMix (BaseClass) {
  /** @class ClusterMixed */
  class ClusterMixed extends BaseClass {
    get $$clusterMixed () {
      return true
    }

    constructor () {
      super(...arguments)
      const s = this
      s._clusterWorkerListners = {}
    }

    setupCluster () {
      const s = this
      if (cluster.isMaster) {
        const {workers} = cluster
        for (const id of Object.keys(workers || {})) {
          s.bindClusterWorker(workers[id])
        }
        cluster.setMaxListeners(cluster.getMaxListeners() + 2)
        cluster.addListener('online', (worker) => s.bindClusterWorker(worker))
        cluster.addListener('exit', (worker) => s.unbindClusterWorker(worker))
      } else {
        const {worker} = cluster
        s.bindClusterWorker(worker)
      }
    }

    bindClusterWorker (worker) {
      const s = this
      const resourceName = String(clayResourceName(s))
      const listeners = {
        'message': async ({$$clay, $$from, $$resource, event, data}) => {
          if (!$$clay) {
            return
          }
          if (resourceName !== $$resource) {
            return
          }

          if (/^cly:entity/.test(event)) {
            data = await s.restoreClusterEventData(data)
          }
          for (const listener of (s.listeners(event) || [])) {
            listener(data)
          }
          if (cluster.isMaster) {
            const {workers} = cluster
            for (const id of Object.keys(workers)) {
              const worker = workers[id]
              const skip = String(id) === String($$from)
              if (skip) {
                continue
              }
              worker.send({$$clay, $$resource, $$from, event, data})
            }
          }
        }
      }
      s._clusterWorkerListners[worker.id] = listeners
      const events = Object.keys(listeners)
      worker.setMaxListeners(worker.getMaxListeners() + events.length)
{'fraction_non_alphanumeric': 0.12649649875762367, 'fraction_numerical': 0.00045177320984865596, 'mean_word_length': 1.981818181818182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4479787', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1216, 'n_words': 279}