diff --git a/src/Command/WaveFunctionCollapseCommand.php b/src/Command/WaveFunctionCollapseCommand.php index 557ae1c..6b17775 100644 --- a/src/Command/WaveFunctionCollapseCommand.php +++ b/src/Command/WaveFunctionCollapseCommand.php @@ -36,6 +36,7 @@ protected function configure(): void ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the grid', 5) ->addOption('height', null, InputOption::VALUE_OPTIONAL, 'Height of the grid', 5) ->addOption('dataset', null, InputOption::VALUE_OPTIONAL, 'Dataset to use', DataSetEnumType::CIRCUIT_CODING_TRAIN->value) + ->addOption('memory', null, InputOption::VALUE_OPTIONAL, 'Set memory limit') ; } @@ -43,6 +44,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); + if ($memory = $input->getOption('memory')) { + ini_set('memory_limit', $memory . 'M'); + } + $width = (int) $input->getOption('width'); $height = (int) $input->getOption('height'); $dataSetValue = $input->getOption('dataset'); diff --git a/src/Scheduler/Task/FlowTask.php b/src/Scheduler/Task/FlowTask.php index 35e3f5c..04944c2 100644 --- a/src/Scheduler/Task/FlowTask.php +++ b/src/Scheduler/Task/FlowTask.php @@ -7,12 +7,14 @@ use App\EnumType\WaveFunctionCollapse\DataSetEnumType; use App\Flow\WaveFunctionCollapse\FlowFactory; use Flow\Ip; +use Symfony\Component\Mime\Part\File; use Symfony\Component\Notifier\Bridge\Twitter\TwitterOptions; use Symfony\Component\Notifier\ChatterInterface; use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Scheduler\Attribute\AsCronTask; -#[AsCronTask('0 7 * * *')] +// #[AsCronTask('0 7 * * *', arguments: ['memory' => 256, 'width' => 5, 'height' => 5])] +#[AsCronTask('* * * * *', arguments: ['memory' => 256, 'width' => 5, 'height' => 5])] final class FlowTask { public function __construct( @@ -20,13 +22,17 @@ public function __construct( private ChatterInterface $chatter, ) {} - public function __invoke(): void + public function __invoke(int $memory, int $width, int $height): void { + if ($memory) { + ini_set('memory_limit', $memory . 'M'); + } + $dataSet = DataSetEnumType::cases()[array_rand(DataSetEnumType::cases())]; $flow = $this->flowFactory->doMp4($dataSet) ->fn(function ($path) { - $message = (new ChatMessage('Daily Flow generation.', (new TwitterOptions())->attachVideo($path))) + $message = (new ChatMessage('Daily Flow generation.', (new TwitterOptions())->attachVideo(new File($path)))) ->transport('twitter') ; $this->chatter->send($message); @@ -35,7 +41,7 @@ public function __invoke(): void }) ; - $flow(new Ip([5, 5, $dataSet])); + $flow(new Ip([$width, $height, $dataSet])); $flow->await(); }