AppsDevTeam / command-lock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

command-lock

namespace App\Commands;

use ADT\CommandLock\CommandLock;
use ADT\CommandLock\Storage\FileSystemStorage;
use Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

abstract class Command extends \Symfony\Component\Console\Command\Command
{
	use CommandLock;

	private string $locksDir;

	abstract protected function executeCommand(InputInterface $input, OutputInterface $output): int;

	public function setLocksDir(string $locksDir)
	{
		$this->locksDir = $locksDir;
	}

	/**
	 * @throws Exception
	 */
	protected function execute(InputInterface $input, OutputInterface $output): int
	{
		$this->setStorage(new FileSystemStorage($this->locksDir));

		$this->lock();

		$status = $this->executeCommand($input, $output);

		$this->unlock();

		return $status;
	}
}

About

License:MIT License


Languages

Language:PHP 69.9%Language:Makefile 19.1%Language:Shell 6.3%Language:Dockerfile 4.7%