<commit_before>'use strict';

const Router = require('koa-router');


module.exports = (manager) => {
    const router = new Router();

    router.get('/', getInstances);
    router.post('/stop', removeInstance);

    return router.routes();


    ////////////

    function *getInstances() {
        this.status = 200;
        this.body = manager.stats;
    }

    function *removeInstance() {
        const name = this.request.body['name'];
        if (!name || name.length <= 0) {
            throw new Error('Name not found');
        }

        const promise = manager.removeInstance(name);
        if (!promise) {
            this.status = 404;
            this.body = `Proxy ${name} not found`;
            return;
        }

        yield promise;

        this.status = 200;
        this.body = {
            alive: manager.aliveInstances.length,
        };
    }
};
<commit_msg>fix(commander): manager fast remove instance from user<commit_after>'use strict';

const Router = require('koa-router'),
    winston = require('winston');


module.exports = (manager) => {
    const router = new Router();

    router.get('/', getInstances);
    router.post('/stop', removeInstance);

    return router.routes();


    ////////////

    function *getInstances() {
        this.status = 200;
        this.body = manager.stats;
    }

    function *removeInstance() {
        const name = this.request.body['name'];
        if (!name || name.length <= 0) {
            throw new Error('Name not found');
        }

        try {
            const promise = manager.removeInstance(name);
            if (!promise) {
                this.status = 404;
                this.body = `Proxy ${name} not found`;
                return;
            }

            yield promise;

            this.status = 200;
            this.body = {
                alive: manager.aliveInstances.length,
            };
        }
        catch (err) {
            winston.error('[Commander] Error: Cannot remove instance %s:', name, err);

            this.status = 500;
            this.body = `Error: Cannot remove instance ${name}: ${err.toString()}`;
        }
    }
};

{'fraction_non_alphanumeric': 0.14531104921077065, 'fraction_numerical': 0.010677808727948004, 'mean_word_length': 1.7038895859473024, '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': '5904206', 'n_tokens_mistral': 633, 'n_tokens_neox': 586, 'n_words': 144}