chesszebra/jobsystem

一个PHP库,提供用于运行后台作业的作业系统。

0.1.0 2020-10-18 13:51 UTC

This package is auto-updated.

Last update: 2024-09-18 22:20:32 UTC


README

Build Status

一个提供执行工作作业支持的PHP库。

安装

composer require chesszebra/jobsystem

使用方法

添加作业

<?php

// For this example we use Pheanstalk
$connection = new Pheanstalk\Pheanstalk('localhost');

// The storage to store jobs in
$storage = new ChessZebra\JobSystem\Storage\Pheanstalk($connection);
$storage->addJob(new \ChessZebra\JobSystem\Job\Job('my-worker', [
    'some' => 'parameter',
]));

执行作业

<?php

// For this example we use Pheanstalk
$connection = new Pheanstalk\Pheanstalk('localhost');

// The storage where we retrieve jobs from.
$storage = new ChessZebra\JobSystem\Storage\Pheanstalk($connection);

// Setup a logger which is used to write information
$logger = ...; // Any PSR-3 compatible logger.

// A container with all workers
$workers = ...; // Any PSR-11 compatible container.

// Now create the client and run it. 
$client = new ChessZebra\JobSystem\Client($storage, $logger, $workers);
$client->run();

开发

使用Docker运行composer和phpunit

docker run --rm -it -v $(pwd):/data chesszebra/composer install 
docker run --rm -it -v $(pwd):/data chesszebra/phpunit