Skip to content

Commit

Permalink
🎨 Add memory params for WFC
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Nov 18, 2024
1 parent dce8bfb commit 18afbb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Command/WaveFunctionCollapseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ 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')
;
}

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');
Expand Down
14 changes: 10 additions & 4 deletions src/Scheduler/Task/FlowTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@
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(
private FlowFactory $flowFactory,
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);
Expand All @@ -35,7 +41,7 @@ public function __invoke(): void
})
;

$flow(new Ip([5, 5, $dataSet]));
$flow(new Ip([$width, $height, $dataSet]));

$flow->await();
}
Expand Down

0 comments on commit 18afbb3

Please sign in to comment.