<commit_before>var logger = require('winston');
var configuration = require('./ConfigurationLoader');

/**
 * Constructor.
 * The JobHandler executes jobs which were added via the addJob to a queue. The jobs in that queue will be executed automatically.
 * There exist two execution modes.
 * 'Discard': One job will be allowed in the queue and all further jobs will be discarded.
 * 'Queue': The jobs will be executed in FIFO order.
 * The JobHandler allows access to the running job to retrieve some information about the current run status.
 * **/
var JobHandler = function() {
    this.isJobRunning = false;
    this.behaviour = configuration.getWorkingMode();
    this.jobQueue = [];
    this.runningJob = null;
};

/* ----- Getter ----- */

JobHandler.prototype.isJobRunning = function () {
    return this.isJobRunning;
};

JobHandler.prototype.getRunningJob = function () {
    return this.runningJob;
};

/* ----- Setter/Adder ----- */

/**
 * Adds a job to the queue.
 *
 * @param job The job which will be added/discarded to the queue, depending on the execution mode.
 * **/
JobHandler.prototype.addJob = function (job) {
    // Discard job if something is already in the queue
    if(this.behaviour == 0
        && (this.jobQueue.length > 1
        || this.isJobRunning)) {
        logger.info('There is already a job being executed. Execution behaviour is set to discard. Discarding new job.');
    // Add job to queue
    } else {
        logger.info('Adding new job to the queue:', job.prototype.getJobName());
        this.jobQueue.push(job);
        this.__executeJob();
    }
};

/* ----- Privates ----- */

/**
 * Execute a job. After a job execution is finished, the next job will be executed automatically.
 * **/
JobHandler.prototype.__executeJob = function() {
    var that = this;

    // If there exists a job, then change the state to isRunning and execute the job
    if(this.jobQueue.length >= 1 && !this.isJobRunning) {
        this.isJobRunning = true;
        this.runningJob = this.jobQueue.shift();

        // ToDo: Error handling: If something happens, the job locks the execution queue forever
        logger.info('Executing job:', this.runningJob.prototype.getJobName());
        this.runningJob.execute(function () {
            that.isJobRunning = false;
            that.runningJob = null;

            // Execute the next job
            that.__executeJob();
        });
    } else {
        // ToDo: Some Error Handling or do nothing because there is nothing to do?
    }
};

module.exports = new JobHandler();<commit_msg>Removes some direct prototype accesses which I missed the last time.<commit_after>var logger = require('winston');
var configuration = require('./ConfigurationLoader');

/**
 * Constructor.
 * The JobHandler executes jobs which were added via the addJob to a queue. The jobs in that queue will be executed automatically.
 * There exist two execution modes.
 * 'Discard': One job will be allowed in the queue and all further jobs will be discarded.
 * 'Queue': The jobs will be executed in FIFO order.
 * The JobHandler allows access to the running job to retrieve some information about the current run status.
 * **/
var JobHandler = function() {
    this.isJobRunning = false;
    this.behaviour = configuration.getWorkingMode();
    this.jobQueue = [];
    this.runningJob = null;
};

/* ----- Getter ----- */

JobHandler.prototype.isJobRunning = function () {
    return this.isJobRunning;
};

JobHandler.prototype.getRunningJob = function () {
    return this.runningJob;
};

/* ----- Setter/Adder ----- */

/**
 * Adds a job to the queue.
 *
 * @param job The job which will be added/discarded to the queue, depending on the execution mode.
 * **/
JobHandler.prototype.addJob = function (job) {
    try {
        // Discard job if something is already in the queue
        if (this.behaviour == 0
            && (this.jobQueue.length > 1
            || this.isJobRunning)) {
            logger.info('There is already a job being executed. Execution behaviour is set to discard. Discarding new job.');
            // Add job to queue
        } else {
            logger.info('Adding new job to the queue:', job.getJobName());
            this.jobQueue.push(job);
            this.__executeJob();
        }
    } catch (exception){
        logger.error(exception);
    }
};

/* ----- Privates ----- */

/**
 * Execute a job. After a job execution is finished, the next job will be executed automatically.
 * **/
JobHandler.prototype.__executeJob = function() {
    var that = this;

    try {
        // If there exists a job, then change the state to isRunning and execute the job
        if (this.jobQueue.length >= 1 && !this.isJobRunning) {
            this.isJobRunning = true;
            this.runningJob = this.jobQueue.shift();

            // ToDo: Error handling: If something happens, the job locks the execution queue forever
            logger.info('Executing job:', this.runningJob.getJobName());
            this.runningJob.execute(function () {
                that.isJobRunning = false;
                that.runningJob = null;

                // Execute the next job
                that.__executeJob();
            });
        } else {
            // ToDo: Some Error Handling or do nothing because there is nothing to do?
        }
    } catch (exception) {
        logger.error(exception);
    }
};

module.exports = new JobHandler();
{'fraction_non_alphanumeric': 0.11449115044247787, 'fraction_numerical': 0.0011061946902654867, 'mean_word_length': 2.4797947402180887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6394996', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1429, 'n_words': 523}