- Add to cron
* * * * * php bin/console cron:run - Create a class that implements
\Byfareska\Cron\Task\ScheduledTask, for example:
final class DeleteFileEveryHourTask implements ScheduledTask {
public function cronInvoke(DateTimeInterface $now, bool $forceRun, OutputInterface $output): bool
{
if($forceRun || $now->format('i') === '0'){
$this();
return true;
}
return false;
}
public function __invoke(): void
{
unlink('/var/example');
}
}php bin/console cron:run --task=App\\Task\\DeleteFileEveryHourTask,App\\Task\\AnotherTask
php bin/console debug:container --tag=cron.task