<commit_before>
from KBParallel.Task import Task
from KBParallel.Runners import ParallelRunner, ParallelLocalRunner, SerialLocalRunner


class BatchRunner(object):

    def __init__(self, callback_url, cfg, token):
        self.callback_url = callback_url
        self.cfg = cfg
        self.token = token


    def run(self, parameters):

        validated_params = self.validate_params(parameters)
        tasks = self.build_tasks(validated_params['tasks'])

        max_retries = 1

        if validated_params['runner'] == 'local_serial':
            slr = SerialLocalRunner(tasks, max_retries, self.callback_url)
            return slr.run()

        if validated_params['runner'] == 'local_parallel':
            # tasks, max_retries, n_concurrent_tasks, total_checks_per_min, callback_url
            total_checks_per_min = 30
            plr = ParallelLocalRunner(tasks, max_retries, validated_params['concurrent_local_tasks'],
                                      total_checks_per_min, self.callback_url)
            return plr.run()

        if validated_params['runner'] == 'parallel':
            # tasks, max_retries, n_concurrent_tasks, total_checks_per_min, callback_url
            total_checks_per_min = 30
            plr = ParallelLocalRunner(tasks, max_retries, validated_params['concurrent_local_tasks'],
                                      validated_params['concurrent_local_tasks'], total_checks_per_min,
                                      total_checks_per_min, self.callback_url)
            return plr.run()

        # this path should not be reachable
        raise ValueError('Unknown runner type, or other strange internal error')



    def build_tasks(self, task_specs):<commit_msg>bug fix<commit_after>
from KBParallel.Task import Task
from KBParallel.Runners import ParallelRunner, ParallelLocalRunner, SerialLocalRunner


class BatchRunner(object):

    def __init__(self, callback_url, cfg, token):
        self.callback_url = callback_url
        self.cfg = cfg
        self.token = token


    def run(self, parameters):

        validated_params = self.validate_params(parameters)
        tasks = self.build_tasks(validated_params['tasks'])

        max_retries = 1

        if validated_params['runner'] == 'local_serial':
            slr = SerialLocalRunner(tasks, max_retries, self.callback_url)
            return slr.run()

        if validated_params['runner'] == 'local_parallel':
            # tasks, max_retries, n_concurrent_tasks, total_checks_per_min, callback_url
            total_checks_per_min = 30
            plr = ParallelLocalRunner(tasks, max_retries, validated_params['concurrent_local_tasks'],
                                      total_checks_per_min, self.callback_url)
            return plr.run()

        if validated_params['runner'] == 'parallel':
            # tasks, max_retries, n_concurrent_tasks, total_checks_per_min, callback_url
            total_checks_per_min = 30
            plr = ParallelRunner(tasks, max_retries, validated_params['concurrent_local_tasks'],
                                 validated_params['concurrent_local_tasks'], total_checks_per_min,
                                 total_checks_per_min, self.callback_url)
            return plr.run()

        # this path should not be reachable
        raise ValueError('Unknown runner type, or other strange internal error')



    def build_tasks(self, task_specs):
{'fraction_non_alphanumeric': 0.07789165446559297, 'fraction_numerical': 0.0029282576866764276, 'mean_word_length': 2.626326963906582, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3076461', 'n_tokens_mistral': 967, 'n_tokens_neox': 904, 'n_words': 196}