-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scan can't find new cron #44
Comments
As a workaround, you may specify the command schedule inside your configuration using a dedicated tag as such: App\Command\MyFancyCommand:
tags:
- { name: shapecode_cron.cron_job, expression: '@daily' } Unfortunately I am currently unable to verify whether this command is still considered lazy. |
i want to use this Bundle with SF6 an possible Solution for that is, to use the new TaggedIterator(SF5.3) to get all Commands. |
I'll take a look at it ;) |
as a POC: `class GetTaggedService
} |
my workaround:
...
public function onLoadJobs(LoadJobsEvent $event): void
{
foreach ($this->application->all() as $command) {
if ($command instanceof LazyCommand) {
$command = $command->getCommand();
}
// Check for an @CronJob annotation
$reflectionClass = new ReflectionClass($command);
foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
if (! ($annotation instanceof CronJob)) {
continue;
}
$arguments = $annotation->arguments;
$maxInstances = $annotation->maxInstances;
$schedule = $annotation->value;
assert(is_string($schedule));
$meta = CronJobMetadata::createByCommand($schedule, $command, $arguments, $maxInstances);
$event->addJob($meta);
}
}
}
... |
Hi,
I had a problem in Symfony 5.3 with the shapecode:cron:scan command because it couldn't find any CronJob.
I got deeper and I found that the problem was here: https://github.com/shapecode/cron-bundle/blob/master/src/EventListener/AnnotationJobLoaderListener.php#L40
Because of that https://symfony.com/blog/new-in-symfony-5-3-lazy-command-description
In my command I had a description like
class MyCommand extends Command { protected static $defaultDescription = '...';
and that was the problem!
With the description, the
$this->application->all()
return Symfony\Component\Console\Command\LazyCommand , instead of MyCommand class.Than the LazyCommand class is used as argument for the reflection in the next line
$reflClass = new ReflectionClass($command);
Removing the description from MyCommand worked fine.
I hope that this little explanation could help someone when updating symfony
best regards
The text was updated successfully, but these errors were encountered: