<commit_before>const mongoose = require('mongoose');
const cluster = require('cluster');
const os = require('os');

const ClassDefinition = require('./app/class-definition');

class Core {

    constructor() {

        this._classDefinition = new ClassDefinition('core', 'core');

        this.ready = false;
        this.consoleMode = false;

        this.util = {};
        this.module = {};
        this.model = {};

    }

    init(config) {

        if (cluster.isMaster) {
            // Count the machine's CPUs
            var cpuCount = os.cpus().length;

            // Create a worker for each CPU
            for (var i = 0; i < cpuCount; i++) {
                cluster.fork();
            }

            return;

        }

        this.config = require('./app/config');

        // instantiate object util at first, because it used to merge configs
        this.util.object = this._instantiate(this.config.util.object);

        // merge application specific config with default config
        if ('object' === typeof config) this.util.object.merge(this.config, config);

        // instantiate error module at first
        this.module.error = this._instantiate(this.config.module.error);

        // handle uncaught exceptions
        process.on('uncaughtException', this.module.error.handleUncaughtException.bind(this.module.error));

        // add model classes to core
        for (let model in this.config.model) {

            let schema = mongoose.Schema(this.config.model[model].config.schema);
            this.model[model] = mongoose.model(model, schema)

        }

        // instantiate all classes except models
        for (let namespace in this.config) {

            if ('model' === namespace) {
                continue;
            }

            let instance = this._instantiate(this.config[namespace]);

            if (null !== instance) {
                this[namespace] = instance;
            }
        }

        // check ready state modules
        this._startCheckModules();

        // detect console mode
        if ('string' === typeof process.argv[2]) {
            this.consoleMode = true;
        }

        if (this.consoleMode) {
            this._loadFixtures();
        } else {
            this.module.server.start();
        }

        // TODO: only in main cluster process
        this.module.logger.log('application run in env: ' + process.env.NODE_ENV);

    }

    _startCheckModules() {

        let states = {};

        setInterval(() => {

            let ready = true;

            for (let name in this.module) {

                if (undefined === states[name]) {
                    states[name] = 0;
                }

                if (undefined === this.module[name].ready || true === this.module[name].ready) {
                    states[name] = 0;
                    return;
                }

                ready = false;
                states[name]++;
                process.stdout.write('wait for module "' + name + '" ' + states[name] + '\r');

            }<commit_msg>fix log in core for env<commit_after>const mongoose = require('mongoose');
const cluster = require('cluster');
const os = require('os');

const ClassDefinition = require('./app/class-definition');

class Core {

    constructor() {

        this._classDefinition = new ClassDefinition('core', 'core');

        this.ready = false;
        this.consoleMode = false;

        this.util = {};
        this.module = {};
        this.model = {};

    }

    init(config) {

        if (cluster.isMaster) {
            // Count the machine's CPUs
            var cpuCount = os.cpus().length;

            // Create a worker for each CPU
            for (var i = 0; i < cpuCount; i++) {
                cluster.fork();
            }

            return;

        }

        this.config = require('./app/config');

        // instantiate object util at first, because it used to merge configs
        this.util.object = this._instantiate(this.config.util.object);

        // merge application specific config with default config
        if ('object' === typeof config) this.util.object.merge(this.config, config);

        // instantiate error module at first
        this.module.error = this._instantiate(this.config.module.error);

        // handle uncaught exceptions
        process.on('uncaughtException', this.module.error.handleUncaughtException.bind(this.module.error));

        // add model classes to core
        for (let model in this.config.model) {

            let schema = mongoose.Schema(this.config.model[model].config.schema);
            this.model[model] = mongoose.model(model, schema)

        }

        // instantiate all classes except models
        for (let namespace in this.config) {

            if ('model' === namespace) {
                continue;
            }

            let instance = this._instantiate(this.config[namespace]);

            if (null !== instance) {
                this[namespace] = instance;
            }
        }

        // check ready state modules
        this._startCheckModules();

        // detect console mode
        if ('string' === typeof process.argv[2]) {
            this.consoleMode = true;
        }

        if (this.consoleMode) {
            this._loadFixtures();
        } else {
            this.module.server.start();
        }

        // TODO: only in main cluster process
        this.module.logger.log('application run in env: ' + process.env.NODE_ENV, '', this._classDefinition, undefined, 6);

    }

    _startCheckModules() {

        let states = {};

        setInterval(() => {

            let ready = true;

            for (let name in this.module) {

                if (undefined === states[name]) {
                    states[name] = 0;
                }

                if (undefined === this.module[name].ready || true === this.module[name].ready) {
                    states[name] = 0;
                    return;
                }

                ready = false;
                states[name]++;
                process.stdout.write('wait for module "' + name + '" ' + states[name] + '\r');

            }
{'fraction_non_alphanumeric': 0.12262465486438201, 'fraction_numerical': 0.0014617508526879974, 'mean_word_length': 1.632749038050449, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6448064', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1540, 'n_words': 394}