Trait for only one instance of beanstalk worker
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fgh151/yii2-beanstalk-singleton "*"
or add
"fgh151/yii2-beanstalk-singleton": "*"
to the require section of your composer.json
file.
Once the extension is installed, add trait to beanstalk controller
class TestController extends udokmeci\yii2beanstalk\BeanstalkController
{
use fgh151\beanstalk\Singleton;
}
Now you have additional commands:
./yii test/status
it will print pid of current process or "Not active" if worker not run
./yii test/halt
it will halt current worker
If you use php >= 5.4, you mas override construct and destruct methods:
class BuildController extends BeanstalkController
{
use fgh151\beanstalk\Singleton {
Singleton::__construct as private __TraitConstruct;
Singleton::__destruct as private __TraitDestruct;
}
public function __construct($id, Module $module, array $config)
{
$this->__TraitConstruct($id, $module, $config);
}
public function __destruct()
{
$this->__TraitDestruct();
}
}
Comments