eschmar/taskchain-bundle

为symfony2简化cronjobs。

安装: 29

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v0.1 2014-02-17 17:39 UTC

This package is auto-updated.

Last update: 2024-09-11 20:06:55 UTC


README

使用此包,您可以分配服务到任务链,任务链可以通过控制台执行。

安装

Composer (Packagist)

"require": {
	"eschmar/taskchain-bundle": "dev-master"
},

app/Appkernel.php

new Eschmar\TaskChainBundle\EschmarTaskChainBundle(),

使用

以下示例创建一个名为 Test Task 的新任务,该任务将在返回之前简单地等待3秒。您的服务必须扩展提供的抽象类 TaskAbstract

src/Acme/HelloBundle/Task/TestTask.php

namespace Acme\HelloBundle\Task;

use Eschmar\TaskChainBundle\Task\TaskAbstract;

class TestTask extends TaskAbstract
{
	protected function init() {
		$this->name = 'Test Task';
		$this->groups[] = 'test';
	}

	public function execute() {
		sleep(3);
		return true;
	}
}

src/Acme/HelloBundle/Resources/config/services.yml

acme_hello.taskchain_test:
    class: Acme\HelloBundle\Task\TestTask
    tags:
        - { name: taskchain }

现在您可以执行控制台命令

php app/console taskchain [<group>] [--inset]

该命令将执行所有满足组要求的标记服务。使用 --inset 选项排除一个组但执行所有其他组。

输出

$ app/console taskchain

   ______           __      ________          _
  /_  __/___ ______/ /__   / ____/ /_  ____ _(_)___
   / / / __ `/ ___/ //_/  / /   / __ \/ __ `/ / __ \
  / / / /_/ (__  ) ,<    / /___/ / / / /_/ / / / / /
 /_/  \__,_/____/_/|_|   \____/_/ /_/\__,_/_/_/ /_/

 --------------------------- START ---------------------------

 . Test Task... success

 ---------------------------- END ----------------------------

许可证

MIT许可证