2017 © Pedro Peláez
 

library singleton-command

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

image

jced-artem/singleton-command

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

  • Friday, December 9, 2016
  • by jced_artem
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 14 % Grown

The README.md

singleton-command

Symfony singleton command. Command that can't be run in parallel before previous process stopped. If you need to simply run symfony command only in one process and you don't want to use and manage lock files by yourself - this class is what you need :), (*1)

Require

  1. symfony/console
  2. jced-artem/lock-service - uses this package to replace LockHandler because it can't work with several hosts. This is important here because command can be launched in several servers as cron with shared folder.

Install

composer require jced-artem/singleton-command, (*2)

Example

class JobCommand extends SingletonCommand implements SingletonCommandInterface
{
    protected function configure()
    {
        $this
            ->setName('cron:job')
            ->addArgument('someArgument', InputArgument::REQUIRED)
        ;
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    protected function beforeLock(InputInterface $input, OutputInterface $output)
    {
        // You can create dynamic lock-names if you need. If don't - just remove this method.
        $this->setLockName($this->getName() . ':' . $input->getArgument('someArgument'));
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return bool
     */
    public function lockExecute(InputInterface $input, OutputInterface $output)
    {
        // command code here
    }
}

And you need to use this command as service, so, your services.yml should looks like this:, (*3)

parameters:
    lock_path: '/path/to/shared/folder/locks'

services:
    lock_service:
        class: AppBundle\Service\LockService
        arguments: ['%lock_path%']
        shared: false # shouldn't be shared if you want to have commands with different lock paths.
    command.cron_job:
        class: AppBundle\Command\JobCommand
        arguments: ['@lock_service']
        tags:
            - { name: console.command }

The Versions

09/12 2016

dev-master

9999999-dev https://github.com/jced-artem

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Jced

command symfony lock singleton

09/12 2016

1.0.2

1.0.2.0 https://github.com/jced-artem

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Jced

command symfony lock singleton

09/12 2016

1.0.1

1.0.1.0 https://github.com/jced-artem

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Jced

command symfony lock singleton

09/12 2016

1.0.0

1.0.0.0 https://github.com/jced-artem

Symfony singleton command. Command that can't be run in parallel before previous process stopped.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Artem Jced

command symfony lock singleton