<commit_before>// Copyright 2014-2015, Renasar Technologies Inc.
/* jshint: node:true */

'use strict';

var di = require('di');

module.exports = runGraphJobFactory;
di.annotate(runGraphJobFactory, new di.Provide('Job.Graph.Run'));
    di.annotate(runGraphJobFactory,
    new di.Inject(
        'Job.Base',
        'Protocol.TaskGraphRunner',
        'Logger',
        'Assert',
        'uuid',
        'Util',
        'Q',
        '_'
    )
);
function runGraphJobFactory(BaseJob, taskGraphProtocol, Logger, assert, uuid, util) {
    var logger = Logger.initialize(runGraphJobFactory);

    /**
     *
     * @param {Object} options
     * @param {Object} context
     * @param {String} taskId
     * @constructor
     */
    function RunGraphJob(options, context, taskId) {
        RunGraphJob.super_.call(this, logger, options, context, taskId);

        assert.string(this.options.graphName);
        assert.object(this.options.graphOptions);
        // context.target is optional depending on what graph is being run
        assert.object(context);

        if (!this.options.instanceId) {
            this.options.instanceId = uuid.v4();
        }
        this.graphId = this.options.instanceId;
        this.options.graphOptions.instanceId = this.graphId;
    }
    util.inherits(RunGraphJob, BaseJob);

    /**
     * @memberOf RunGraphJob
     */
    RunGraphJob.prototype._run = function() {
        var self = this;

        logger.info("Running run-graph job.", {
            options: self.options,
            context: self.context,
            taskId: self.taskId
        });

        this._subscribeGraphFinished(function(status) {
            assert.string(status);
            if (status === 'succeeded') {
                self._done();
            } else {
                self._done(new Error("Graph " + self.graphId +
                        " failed with status " + status));
            }
        });

        taskGraphProtocol.runTaskGraph(
                this.options.graphName, this.options.graphOptions, this.options.graphOptions.target)
        .then(function(message) {
            try {
                // TODO: swap out with errors once we can do that over the bus protocol
                assert.uuid(message);
            } catch (e) {
                self._done(new Error("Unable to start graph: " + message));
            }
        })
        .catch(function(error) {
            self._done(error);
        });
    };

    return RunGraphJob;
}
<commit_msg>Fixing run graph job crashing because of return from protocol runTaskGraph<commit_after>// Copyright 2014-2015, Renasar Technologies Inc.
/* jshint: node:true */

'use strict';

var di = require('di');

module.exports = runGraphJobFactory;
di.annotate(runGraphJobFactory, new di.Provide('Job.Graph.Run'));
    di.annotate(runGraphJobFactory,
    new di.Inject(
        'Job.Base',
        'Protocol.TaskGraphRunner',
        'Logger',
        'Assert',
        'uuid',
        'Util',
        'Q',
        '_'
    )
);
function runGraphJobFactory(BaseJob, taskGraphProtocol, Logger, assert, uuid, util) {
    var logger = Logger.initialize(runGraphJobFactory);

    /**
     *
     * @param {Object} options
     * @param {Object} context
     * @param {String} taskId
     * @constructor
     */
    function RunGraphJob(options, context, taskId) {
        RunGraphJob.super_.call(this, logger, options, context, taskId);

        assert.string(this.options.graphName);
        assert.object(this.options.graphOptions);
        // context.target is optional depending on what graph is being run
        assert.object(context);

        if (!this.options.instanceId) {
            this.options.instanceId = uuid.v4();
        }
        this.graphId = this.options.instanceId;
        this.options.graphOptions.instanceId = this.graphId;
    }
    util.inherits(RunGraphJob, BaseJob);

    /**
     * @memberOf RunGraphJob
     */
    RunGraphJob.prototype._run = function() {
        var self = this;

        logger.info("Running run-graph job.", {
            options: self.options,
            context: self.context,
            taskId: self.taskId
        });

        this._subscribeGraphFinished(function(status) {
            assert.string(status);
            if (status === 'succeeded') {
                self._done();
            } else {
                self._done(new Error("Graph " + self.graphId +
                        " failed with status " + status));
            }
        });

        taskGraphProtocol.runTaskGraph(
                this.options.graphName, this.options.graphOptions, this.options.graphOptions.target)
        .then(function(message) {
            try {
                // TODO: swap out with errors once we can do that over the bus protocol
                assert.uuid(message.instanceId);
            } catch (e) {
                self._done(new Error("Unable to start graph for task " + self.taskId +
                                     " in graph " + this.options.graphName));
            }
        })
        .catch(function(error) {
            self._done(error);
        });
    };

    return RunGraphJob;
}

{'fraction_non_alphanumeric': 0.11832135224402565, 'fraction_numerical': 0.003497182824946571, 'mean_word_length': 1.9134125636672326, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7518697', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1407, 'n_words': 301}