gepur-it / sic-bundle
Single Instance Command Bundle
6.0.0
2021-04-19 09:47 UTC
Requires
- php: ^7.4|^8.0
- symfony/config: ^5.0
- symfony/console: ^5.0
- symfony/dependency-injection: ^5.0
- symfony/event-dispatcher: ^5.0
- symfony/lock: ^5.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Single Instance Console Command Bundle
provides the ability to ban more than one command instance
add bundle in bundles.php
return [
...
GepurIt\SingleInstanceCommandBundle\SingleInstanceCommandBundle::class => ['all' => true],
...
];
to mark command as single instance, add interface to your command, and add method getLockName()
class MyCommand extends Command implements SingleInstanceInterface {
...
/**
* get`s lock name for command execution, based on input
* @param InputInterface $input
* @return string
*/
public function getLockName(InputInterface $input): string
{
return $this->getName();
}
...
}
to allow to run the same command with different args, use $input in getLockName() method
class MyCommand extends Command implements SingleInstanceInterface {
...
/**
* get`s lock name for command execution, based on input
* @param InputInterface $input
* @return string
*/
public function getLockName(InputInterface $input): string
{
return $this->getName().':'.$input->getArgument('myArg');
}
...
}