gepur-it/sic-bundle

Single Instance Command Bundle

Installs: 7 890

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

6.0.0 2021-04-19 09:47 UTC

This package is auto-updated.

Last update: 2024-10-19 17:29:55 UTC


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');
    }
    
    ...
}