<commit_before>const config = require('../../config.js');
const {job, logger} = config;
const utils = require('../../utils');

module.exports = {
    //finds users in the waiting list not in the request list and deletes their jobs
    "pre-request": async (ctx, next) => {
        const {requestState, waitingState} = ctx;
        for (let id in waitingState) {
            if (!requestState[id]) { //user in waiting is not in the requests
                logger.debug(`Stopping job of user ${id}`); //core-hmi-${id}
                const jobName = await job.idToJobName(id);
                await utils.stopJob(jobName, true); //purge the job from Nomad
            }
        }
        next();
    }
}<commit_msg>Send notification to client if their job dies<commit_after>const config = require('../../config.js');
const {job, logger, websocket} = config;
const utils = require('../../utils');

module.exports = {
    //finds users in the waiting list not in the request list and deletes their jobs
    "pre-request": async (ctx, next) => {
        const {requestState, waitingState} = ctx;
        for (let id in waitingState) {
            if (!requestState[id]) { //user in waiting is not in the requests
                logger.debug(`Stopping job of user ${id}`); //core-hmi-${id}
                const jobName = await job.idToJobName(id);
                await utils.stopJob(jobName, true); //purge the job from Nomad
                //inform the client that the job is now gone
                const msgObj = {
                    type: "dead",
                    data: {}
                };
                await websocket.send(id, JSON.stringify(msgObj));
            }
        }
        next();
    }
}
{'fraction_non_alphanumeric': 0.1284296555750146, 'fraction_numerical': 0.0, 'mean_word_length': 1.8952702702702702, 'pattern_counts': {'":': 2, '<': 3, '<?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': '7545456', 'n_tokens_mistral': 471, 'n_tokens_neox': 465, 'n_words': 161}