<commit_before><?php

namespace Phobetor\RabbitMqSupervisorBundle\Services;

use Symfony\Component\Process\Process;

class Supervisor
{
    private $applicationDirectory;
    private $configurationParameter;
    private $identifierParameter;

    public function __construct($applicationDirectory, $configuration, $identifier)
    {
        $this->applicationDirectory = $applicationDirectory;
        $this->configurationParameter = $configuration ? (' --configuration=' . $configuration) : '';
        $this->identifierParameter    = $identifier    ? (' --identifier='    . $identifier)    : '';
    }

    /**
     * Execute a supervisorctl command
     *
     * @param $cmd string supervisorctl command
     * @return \Symfony\Component\Process\Process
     */
    public function execute($cmd)
    {
        $p = new Process(
            sprintf(
                'supervisorctl%1$s %2$s',
                $this->configurationParameter,
                $cmd
            )
        );
        $p->setWorkingDirectory($this->applicationDirectory);
        $p->run();
        $p->wait();
        return $p;
    }

    /**
     * Update configuration and processes
     */
    public function reloadAndUpdate()
    {
        $this->execute('reread');
        $this->execute('update');
    }

    /**
     * Start supervisord if not already running
     */
    public function run()
    {
        $result = $this->execute('status')->getOutput();
        if (strpos($result, 'sock no such file') || strpos($result, 'refused connection')) {
            $p = new Process(
                sprintf(
                    'supervisord%1$s%2$s',
                    $this->configurationParameter,
                    $this->identifierParameter
                )
            );
            $p->setWorkingDirectory($this->applicationDirectory);
            $p->run();
        }
    }
}<commit_msg>Start supervisord in non-blocking mode<commit_after><?php

namespace Phobetor\RabbitMqSupervisorBundle\Services;

use Symfony\Component\Process\Process;

class Supervisor
{
    private $applicationDirectory;
    private $configurationParameter;
    private $identifierParameter;

    public function __construct($applicationDirectory, $configuration, $identifier)
    {
        $this->applicationDirectory = $applicationDirectory;
        $this->configurationParameter = $configuration ? (' --configuration=' . $configuration) : '';
        $this->identifierParameter    = $identifier    ? (' --identifier='    . $identifier)    : '';
    }

    /**
     * Execute a supervisorctl command
     *
     * @param $cmd string supervisorctl command
     * @return \Symfony\Component\Process\Process
     */
    public function execute($cmd)
    {
        $p = new Process(
            sprintf(
                'supervisorctl%1$s %2$s',
                $this->configurationParameter,
                $cmd
            )
        );
        $p->setWorkingDirectory($this->applicationDirectory);
        $p->run();
        return $p;
    }

    /**
     * Update configuration and processes
     */
    public function reloadAndUpdate()
    {
        $this->execute('reread');
        $this->execute('update');
    }

    /**
     * Start supervisord if not already running
     */
    public function run()
    {
        $result = $this->execute('status')->getOutput();
        if (strpos($result, 'sock no such file') || strpos($result, 'refused connection')) {
            $p = new Process(
                sprintf(
                    'supervisord%1$s%2$s',
                    $this->configurationParameter,
                    $this->identifierParameter
                )
            );
            $p->setWorkingDirectory($this->applicationDirectory);
            $p->start();
        }
    }
}
{'fraction_non_alphanumeric': 0.12582781456953643, 'fraction_numerical': 0.002119205298013245, 'mean_word_length': 1.9826224328593998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '5488271', 'n_tokens_mistral': 989, 'n_tokens_neox': 954, 'n_words': 189}