library command-lockable-trait
Symfony console command lockable trait
devcreel/command-lockable-trait
Symfony console command lockable trait
- Sunday, October 15, 2017
- by DevCreel
- Repository
- 0 Watchers
- 0 Stars
- 7 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 3 Versions
- 40 % Grown
Symfony console command lockable trait (very simple emulation of multithreading), (*1)
Installation
Use
Add this to composer.json, (*2)
{
"require": {
"devcreel/command-lockable-trait": "1.0.*-dev"
}
}
Usage
<?php
namespace TestBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use DevCreel\Command\LockableTrait;
class TestCommand extends ContainerAwareCommand
{
use LockableTrait;
//count of threads
private $threadsCount = 5;
protected function configure()
{
$this->setName('test:run');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
//check for free thread
if (!$this->lock()) {
$output->writeln('[' . $this->getName() . '] is already running in another process.');
return 0;
}
//your code...
//release thread
$this->release();
}
}
License
CommandLockableTrait is licensed under the MIT License, (*3)