<commit_before><?php

namespace Hodor\JobQueue;

use Exception;

class Config
{
    /**
     * @var string
     */
    private $config_path;

    /**
     * @var array
     */
    private $config;

    /**
     * @param array $string
     * @param array $config
     */
    public function __construct($config_path, array $config)
    {
        $this->config_path = $config_path;
        $this->config = $config;
    }

    /**
     * @return string
     */
    public function getConfigPath()
    {
        return $this->config_path;
    }

    /**
     * @return array
     */
    public function getDatabaseConfig()
    {
        $superqueuer_config = $this->getOption('superqueue');
        if (!isset($superqueuer_config['database'])) {
            throw new Exception(
                "The 'database' config was not found in the 'superqueue' config."
            );
        }

        return $superqueuer_config['database'];
    }

    /**
     * @return array
     */
    public function getSuperqueueConfig()
    {
        return $this->getOption('superqueue');
    }

    /**
     * @param  string $queue_name
     * @return array
     */
    public function getWorkerQueueConfig($queue_name)
    {
        $config = $this->getQueueConfig(
            $queue_name,
            'worker_queues',
            'worker_queue_defaults'
        );
        $config['key_name'] = $queue_name;
        $config['fetch_count'] = 1;
        $config['queue_type'] = 'worker';
        $config['process_count'] = $config['workers_per_server'];

        return $config;
    }

    /**
     * @param  string $queue_name
     * @return array
     */
    public function getBufferQueueConfig($queue_name)
    {
        $config = $this->getQueueConfig(
            $queue_name,
            'buffer_queues',
            'buffer_queue_defaults'
        );
        $config = array_merge(
            [
                'fetch_count' => 1,
            ],
            $config
        );
        $config['key_name'] = $queue_name;
        $config['queue_type'] = 'bufferer';
        $config['process_count'] = $config['bufferers_per_server'];

        return $config;
    }

    /**
     * @return callable
     */
    public function getJobRunnerFactory()
    {
        $job_runner = $this->getOption('job_runner');

        if (empty($job_runner)) {
            throw new Exception("The 'job_runner' config parameter is required.");
        } elseif (!is_callable($job_runner)) {
            throw new Exception(
                "The provided 'job_runner' config value is not a callable."
            );
        }

        return $job_runner;
    }

    /**
     * @return callable
     */
    public function getWorkerQueueNameFactory()<commit_msg>Remove buffer queue fetch_count option<commit_after><?php

namespace Hodor\JobQueue;

use Exception;

class Config
{
    /**
     * @var string
     */
    private $config_path;

    /**
     * @var array
     */
    private $config;

    /**
     * @param array $string
     * @param array $config
     */
    public function __construct($config_path, array $config)
    {
        $this->config_path = $config_path;
        $this->config = $config;
    }

    /**
     * @return string
     */
    public function getConfigPath()
    {
        return $this->config_path;
    }

    /**
     * @return array
     */
    public function getDatabaseConfig()
    {
        $superqueuer_config = $this->getOption('superqueue');
        if (!isset($superqueuer_config['database'])) {
            throw new Exception(
                "The 'database' config was not found in the 'superqueue' config."
            );
        }

        return $superqueuer_config['database'];
    }

    /**
     * @return array
     */
    public function getSuperqueueConfig()
    {
        return $this->getOption('superqueue');
    }

    /**
     * @param  string $queue_name
     * @return array
     */
    public function getWorkerQueueConfig($queue_name)
    {
        $config = $this->getQueueConfig(
            $queue_name,
            'worker_queues',
            'worker_queue_defaults'
        );
        $config['key_name'] = $queue_name;
        $config['fetch_count'] = 1;
        $config['queue_type'] = 'worker';
        $config['process_count'] = $config['workers_per_server'];

        return $config;
    }

    /**
     * @param  string $queue_name
     * @return array
     */
    public function getBufferQueueConfig($queue_name)
    {
        $config = $this->getQueueConfig(
            $queue_name,
            'buffer_queues',
            'buffer_queue_defaults'
        );
        $config['key_name'] = $queue_name;
        $config['fetch_count'] = 1;
        $config['queue_type'] = 'bufferer';
        $config['process_count'] = $config['bufferers_per_server'];

        return $config;
    }

    /**
     * @return callable
     */
    public function getJobRunnerFactory()
    {
        $job_runner = $this->getOption('job_runner');

        if (empty($job_runner)) {
            throw new Exception("The 'job_runner' config parameter is required.");
        } elseif (!is_callable($job_runner)) {
            throw new Exception(
                "The provided 'job_runner' config value is not a callable."
            );
        }

        return $job_runner;
    }

    /**
     * @return callable
     */
    public function getWorkerQueueNameFactory()
{'fraction_non_alphanumeric': 0.12689885142645424, 'fraction_numerical': 0.0007410151908114116, 'mean_word_length': 1.8687566418703507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '7531865', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1542, 'n_words': 310}