<commit_before><?php

namespace SerendipityHQ\Bundle\CommandsQueuesBundle\Command;

use SerendipityHQ\Bundle\CommandsQueuesBundle\Entity\Job;
use SerendipityHQ\Component\ThenWhen\Strategy\ConstantStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\ExponentialStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\LinearStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\LiveStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\NeverRetryStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\StrategyInterface;
use SerendipityHQ\Component\ThenWhen\Strategy\TimeFixedStrategy;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class SynchOrdersCommand.
 */
class RandomJobsCommand extends AbstractQueuesCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('queues:random-jobs')
            ->setDescription('[INTERNAL] Generates random Jobs to test SHQCommandsQueuesBundle.')
            ->setDefinition(
                new InputDefinition([
                    new InputArgument('how-many-jobs', InputArgument::OPTIONAL, 'How many random Jobs would you like to create?', 10),
                    new InputOption('batch', null, InputOption::VALUE_OPTIONAL, 'The number of Jobs in a batch.', 100),
                    new InputOption('no-future-jobs', null),
                    new InputOption('retry-strategies', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The allowed retry strategies.', ['constant', 'exponential', 'linear', 'live', 'never_retry', 'time_fixed']),
                    new InputOption('time-units', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The allowed time units.', StrategyInterface::TIME_UNITS),
                ])
            );
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return bool
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        parent::execute($input, $output);

        $howManyJobs = (int) $input->getArgument('how-many-jobs');
        $batch = $input->getOption('batch');
        $retryStrategies = $input->getOption('retry-strategies');
        $timeUnits = $input->getOption('time-units');
        $noFutureJobs = $input->getOption('no-future-jobs');

        $this->getIoWriter()->title('SerendipityHQ Queue Bundle Daemon');
        $this->getIoWriter()->info(sprintf('Starting generating %s random jobs...', $howManyJobs));

        // Generate the random jobs
        $progress = new ProgressBar($output, $howManyJobs);
        $progress->setFormat('<success-nobg>%current%</success-nobg>/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%');
        $progress->start();

        $progress->setRedrawFrequency($batch);

        $jobs = [];
        for ($i = 0; $i < $howManyJobs; $i++) {
            // First: we create a Job to push to the queue
            $arguments = '--id='.($i + 1);
            $scheduledJob = new Job('queues:test', $arguments);

            // Set a random retry strategy
            if (0 < count($retryStrategies)) {
                $scheduledJob->setRetryStrategy($this->getRandomRetryStrategy($retryStrategies, $timeUnits));
            }

            // Decide if this will be executed in the future
            if (false === $noFutureJobs) {
                $condition = rand(0, 10);
                if (7 <= $condition) {
                    $days = rand(1, 10);
                    $future = new \DateTime();
                    $future->modify('+'.$days.' day');<commit_msg>Show memory info in progress bar.<commit_after><?php

namespace SerendipityHQ\Bundle\CommandsQueuesBundle\Command;

use SerendipityHQ\Bundle\CommandsQueuesBundle\Entity\Job;
use SerendipityHQ\Component\ThenWhen\Strategy\ConstantStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\ExponentialStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\LinearStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\LiveStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\NeverRetryStrategy;
use SerendipityHQ\Component\ThenWhen\Strategy\StrategyInterface;
use SerendipityHQ\Component\ThenWhen\Strategy\TimeFixedStrategy;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class SynchOrdersCommand.
 */
class RandomJobsCommand extends AbstractQueuesCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('queues:random-jobs')
            ->setDescription('[INTERNAL] Generates random Jobs to test SHQCommandsQueuesBundle.')
            ->setDefinition(
                new InputDefinition([
                    new InputArgument('how-many-jobs', InputArgument::OPTIONAL, 'How many random Jobs would you like to create?', 10),
                    new InputOption('batch', null, InputOption::VALUE_OPTIONAL, 'The number of Jobs in a batch.', 100),
                    new InputOption('no-future-jobs', null),
                    new InputOption('retry-strategies', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The allowed retry strategies.', ['constant', 'exponential', 'linear', 'live', 'never_retry', 'time_fixed']),
                    new InputOption('time-units', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The allowed time units.', StrategyInterface::TIME_UNITS),
                ])
            );
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return bool
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        parent::execute($input, $output);

        $howManyJobs = (int) $input->getArgument('how-many-jobs');
        $batch = $input->getOption('batch');
        $retryStrategies = $input->getOption('retry-strategies');
        $timeUnits = $input->getOption('time-units');
        $noFutureJobs = $input->getOption('no-future-jobs');

        $this->getIoWriter()->title('SerendipityHQ Queue Bundle Daemon');
        $this->getIoWriter()->info(sprintf('Starting generating %s random jobs...', $howManyJobs));

        // Generate the random jobs
        $progress = new ProgressBar($output, $howManyJobs);
        $progress->setFormat('<success-nobg>%current%</success-nobg>/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% (%memory:6s%)');
        $progress->start();

        $progress->setRedrawFrequency($batch);

        $jobs = [];
        for ($i = 0; $i < $howManyJobs; $i++) {
            // First: we create a Job to push to the queue
            $arguments = '--id='.($i + 1);
            $scheduledJob = new Job('queues:test', $arguments);

            // Set a random retry strategy
            if (0 < count($retryStrategies)) {
                $scheduledJob->setRetryStrategy($this->getRandomRetryStrategy($retryStrategies, $timeUnits));
            }

            // Decide if this will be executed in the future
            if (false === $noFutureJobs) {
                $condition = rand(0, 10);
                if (7 <= $condition) {
                    $days = rand(1, 10);
                    $future = new \DateTime();
                    $future->modify('+'.$days.' day');
{'fraction_non_alphanumeric': 0.13298969072164948, 'fraction_numerical': 0.0047680412371134025, 'mean_word_length': 2.95565749235474, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2618918', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2165, 'n_words': 439}