gepur-it / sic-bundle
Single Instance Command Bundle
Installs: 7 895
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
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');
}
...
}