frankdejonge/locked-console-command 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

frankdejonge/locked-console-command

最新稳定版本:3.1.1

Composer 安装命令:

composer require frankdejonge/locked-console-command

包简介

A symfony/console command decorator which locks.

README 文档

README

Author Build Status Quality Score Software License Packagist Version Total Downloads Coverage Status

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.

Credits

The idea wasn't initially mine, I stole it from @Seldaek.

Installation

composer require frankdejonge/locked-console-command

Usage

All you have to do, is wrap the command:

<?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.

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

Configuration

There are two configurable parts to influence locking.

  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:

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

统计信息

  • 总下载量: 6.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 48
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 3
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-03