<commit_before>package io.edgeg.gtm.intellij;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

class GTMRecord {
    private static final String GTM_VER_REQ = ">= 1.2.5";

    private static final Long RECORD_MIN_THRESHOLD = 30000L; // 30 seconds
    private static final String RECORD_COMMAND = "record";
    private static final String STATUS_OPTION = "--status";
    private static final String VERIFY_COMMAND = "verify";

    private static String gtmExePath = null;
    private static String lastRecordPath = null;
    private static Long lastRecordTime = null;

    static Boolean gtmExeFound = false;
    static Boolean gtmVersionOK = true;
    private static GTMConfig cfg = new GTMConfig();

    private static ExecutorService executor = Executors.newSingleThreadExecutor();
    private static Future recordTask;
    private static Long lastRunTime = null;
    private static final Long MAX_RUN_TIME = 2L; // 2 seconds

    static void record(String path, Project project) {
        Runnable r = new Runnable() {
            public void run() {
                runRecord(path, project);
            }
        };
//        GTMConfig.LOG.info(String.format( "Submit record %s", path));
        submitRecord(r);
    }

    private static synchronized void submitRecord(Runnable r) {

        // is there a task running
        if (recordTask != null && !recordTask.isDone()) {
            // make sure it's not a hung process
            if (lastRunTime != null && System.currentTimeMillis() - lastRunTime > MAX_RUN_TIME) {
                // process is hung, cancel it
                recordTask.cancel(true);
                GTMConfig.LOG.warn("Record task was hung, task cancelled");
                recordTask = executor.submit(r);
            }
            return;
        }

        // only submit a task if there isn't one running already
        if (recordTask == null || recordTask.isDone()) {
            recordTask = executor.submit(r);
        }
    }

    private static synchronized void runRecord(String path, Project project) {
//        GTMConfig.LOG.info(String.format("Run record %s", path));

        String status;
        if (StringUtils.isBlank(path)) return;
        if (!gtmExeFound) {
            status = "Error!";<commit_msg>allow runRecord method to run async<commit_after>package io.edgeg.gtm.intellij;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

class GTMRecord {
    private static final String GTM_VER_REQ = ">= 1.2.5";

    private static final Long RECORD_MIN_THRESHOLD = 30000L; // 30 seconds
    private static final String RECORD_COMMAND = "record";
    private static final String STATUS_OPTION = "--status";
    private static final String VERIFY_COMMAND = "verify";

    private static String gtmExePath = null;
    private static String lastRecordPath = null;
    private static Long lastRecordTime = null;

    static Boolean gtmExeFound = false;
    static Boolean gtmVersionOK = true;
    private static GTMConfig cfg = new GTMConfig();

    private static ExecutorService executor = Executors.newSingleThreadExecutor();
    private static Future recordTask;
    private static Long lastRunTime = null;
    private static final Long MAX_RUN_TIME = 2L; // 2 seconds

    static void record(String path, Project project) {
        Runnable r = new Runnable() {
            public void run() {
                runRecord(path, project);
            }
        };
//        GTMConfig.LOG.info(String.format( "Submit record %s", path));
        submitRecord(r);
    }

    private static synchronized void submitRecord(Runnable r) {

        // is there a task running
        if (recordTask != null && !recordTask.isDone()) {
            // make sure it's not a hung process
            if (lastRunTime != null && System.currentTimeMillis() - lastRunTime > MAX_RUN_TIME) {
                // process is hung, cancel it
                recordTask.cancel(true);
                GTMConfig.LOG.warn("Record task was hung, task cancelled");
                recordTask = executor.submit(r);
            }
            return;
        }

        // only submit a task if there isn't one running already
        if (recordTask == null || recordTask.isDone()) {
            recordTask = executor.submit(r);
        }
    }

    private static void runRecord(String path, Project project) {
//        GTMConfig.LOG.info(String.format("Run record %s", path));

        String status;
        if (StringUtils.isBlank(path)) return;
        if (!gtmExeFound) {
            status = "Error!";
{'fraction_non_alphanumeric': 0.09506057781919851, 'fraction_numerical': 0.004473438956197577, 'mean_word_length': 2.7032436162870948, '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': '3856965', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1468, 'n_words': 431}