2017 © Pedro Peláez
 

library locked-console-command

A symfony/console command decorator which locks.

image

frankdejonge/locked-console-command

A symfony/console command decorator which locks.

  • Thursday, June 30, 2016
  • by frankdejonge
  • Repository
  • 1 Watchers
  • 45 Stars
  • 5,598 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 11 Versions
  • 26 % Grown

The README.md

Symfony (or Laravel) Console Locked Commands

Author Build Status Quality Score Software License Packagist Version Total Downloads Coverage Status, (*1)

In some cases, you'll want only one process of a certain command to be able to run at a time. The Command decorator supplied in this package makes this possible by using the LockHandler class from Symfony's Filesystem Component., (*2)

Credits

The idea wasn't initially mine, I stole it from @Seldaek., (*3)

Installation

composer require frankdejonge/locked-console-command

Usage

All you have to do, is wrap the command:, (*4)

<?php

use FrankDeJonge\LockedConsoleCommand\LockedCommandDecorator;
use Symfony\Component\Console\Application;

$application = new Application;
$app->add(new LockedCommandDecorator(new YourConsoleCommand()));
$app->run();

Laravel Usage

use FrankDeJonge\LockedConsoleCommand\LockedCommandDecorator;
Artisan::add(new LockedCommandDecorator(new SomeCommand()));

How does the locking work?

The decorator uses a file lock (supplied by Symfony's LockHandler) to ensure a lock is set before and released after executing the command., (*5)

If a lock is already set for a given task, an info message is shown and the decorated command is prevented from running., (*6)

Configuration

There are two configurable parts to influence locking., (*7)

  1. The lock name
  2. The lock path

Through __constructor argument injection

$command = new LockedCommandDecorator($yourCommand, 'lock-name', '/lock/path'));

Through interface implementations in the wrapper Command

  • Implement FrankDeJonge\LockedConsoleCommand\SpecifiesLockName (::getLockName())
  • Implement FrankDeJonge\LockedConsoleCommand\SpecifiesLockPath (::getLockPath())

The SpecifiesLockName interface is especially handy with dynamic lock names, for example:, (*8)


class SomeQueueWorker extends Command implements SpecifiesLockName { public function getLockName(InputInterface $input) { return 'root:name:'.$input->getArgument('worker-id'); } }

The Versions

30/06 2016

dev-master

9999999-dev

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

30/06 2016

3.1.1

3.1.1.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

30/06 2016

3.1.0

3.1.0.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

29/06 2016

3.0.0

3.0.0.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

28/05 2016

2.0.0

2.0.0.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

09/07 2015

0.1.4

0.1.4.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

09/07 2015

1.0.0

1.0.0.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

05/01 2015

0.1.3

0.1.3.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

03/01 2015

0.1.2

0.1.2.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

03/01 2015

0.1.1

0.1.1.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge

03/01 2015

0.1.0

0.1.0.0

A symfony/console command decorator which locks.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Jonge