<commit_before><?php


namespace JeroenED\Webcron\Command;

use JeroenED\Framework\Kernel;
use JeroenED\Webcron\Repository\Job;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


class DaemonCommand extends Command
{

    protected static $defaultName = 'daemon';
    protected $kernel;

    public function __construct(Kernel $kernel)
    {
        $this->kernel = $kernel;
        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setDescription('The deamon slayer of webcron')
            ->setHelp('This command is the daemon process of webcron, enabling webcron to actually run jobs on time')
            ->addOption('time-limit', 't', InputOption::VALUE_REQUIRED, 'Time limit in seconds before stopping the daemon.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $jobRepo = new Job($this->kernel->getDbCon());
        $timelimit = $input->getOption('time-limit') ?? false;
        if ($timelimit === false) {
            $endofscript = false;
        } elseif(is_numeric($timelimit)) {
            $endofscript = time() + $timelimit;
        } else {
            throw new \InvalidArgumentException('Time limit has incorrect value');
        }

        while(1) {
            if($endofscript !== false && time() > $endofscript) break;
            $jobsToRun = $jobRepo->getJobsDue();
            if(!empty($jobsToRun)) {
                foreach($jobsToRun as $job) {
                    $jobRepo->setJobRunning($job, true);
                    $output->writeln('Runnig Job ' . $job);
                    $pid = pcntl_fork();
                    if($pid == -1) {
                        $jobRepo->RunJob($job);
                        $jobRepo->setJobRunning($job, false);
                    } elseif ($pid == 0) {
                        $dbcon = $this->kernel->getDbCon();
                        $dbcon->close();
                        $dbcon->connect();
                        $jobRepo->RunJob($job);
                        $jobRepo->setJobRunning($job, false);
                        exit;
                    }

                }
            }
            sleep(1);
        }
        $output->writeln('Ended after ' . $timelimit . ' seconds');
        return Command::SUCCESS;
    }
}<commit_msg>BUGFIX: I don't eat brains<commit_after><?php


namespace JeroenED\Webcron\Command;

use JeroenED\Framework\Kernel;
use JeroenED\Webcron\Repository\Job;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


class DaemonCommand extends Command
{

    protected static $defaultName = 'daemon';
    protected $kernel;

    public function __construct(Kernel $kernel)
    {
        $this->kernel = $kernel;
        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setDescription('The deamon slayer of webcron')
            ->setHelp('This command is the daemon process of webcron, enabling webcron to actually run jobs on time')
            ->addOption('time-limit', 't', InputOption::VALUE_REQUIRED, 'Time limit in seconds before stopping the daemon.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $jobRepo = new Job($this->kernel->getDbCon());
        $timelimit = $input->getOption('time-limit') ?? false;
        if ($timelimit === false) {
            $endofscript = false;
        } elseif(is_numeric($timelimit)) {
            $endofscript = time() + $timelimit;
        } else {
            throw new \InvalidArgumentException('Time limit has incorrect value');
        }

        while(1) {
            if($endofscript !== false && time() > $endofscript) break;
            $jobsToRun = $jobRepo->getJobsDue();
            if(!empty($jobsToRun)) {
                foreach($jobsToRun as $job) {
                    $jobRepo->setJobRunning($job, true);
                    $output->writeln('Runnig Job ' . $job);
		    declare(ticks = 1);
		    pcntl_signal(SIGCHLD, SIG_IGN);
		    $pid = pcntl_fork();
                    if($pid == -1) {
                        $jobRepo->RunJob($job);
                        $jobRepo->setJobRunning($job, false);
                    } elseif ($pid == 0) {
                        $dbcon = $this->kernel->getDbCon();
                        $dbcon->close();
                        $dbcon->connect();
                        $jobRepo->RunJob($job);
                        $jobRepo->setJobRunning($job, false);
                        exit;
                    }

                }
            }
            sleep(1);
        }
        $output->writeln('Ended after ' . $timelimit . ' seconds');
        return Command::SUCCESS;
    }
}
{'fraction_non_alphanumeric': 0.1259748050389922, 'fraction_numerical': 0.001799640071985603, 'mean_word_length': 1.8615560640732265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '4527987', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1358, 'n_words': 286}