PHP code example of jc-it / yii2-job-queue
1. Go to this page and download the library: Download jc-it/yii2-job-queue library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jc-it / yii2-job-queue example snippets
'container' => [
'definitions' => [
\League\Tactician\CommandBus::class => function(\yii\di\Container $container) {
return new \League\Tactician\CommandBus([
new \League\Tactician\Handler\CommandHandlerMiddleware (
$container->get(\League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor::class),
$container->get(\League\Tactician\Handler\Locator\HandlerLocator::class),
$container->get(\League\Tactician\Handler\MethodNameInflector\MethodNameInflector::class)
)
]);
},
\JCIT\jobqueue\components\ContainerMapLocator::class => function(\yii\di\Container $container) {
$result = new \JCIT\jobqueue\components\ContainerMapLocator($container);
// Register handlers here
// i.e. $result->setHandlerForCommand(\JCIT\jobqueue\jobs\HelloJob::class, \JCIT\jobqueue\jobHandlers\HelloHandler::class);
return $result;
},
\League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor::class => \League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor::class,
\League\Tactician\Handler\Locator\HandlerLocator::class => \JCIT\jobqueue\components\ContainerMapLocator::class,
\JCIT\jobqueue\interfaces\JobFactoryInterface::class => \JCIT\jobqueue\factories\JobFactory::class,
\JCIT\jobqueue\interfaces\JobQueueInterface::class => \JCIT\jobqueue\components\Beanstalk::class,
\League\Tactician\Handler\MethodNameInflector\MethodNameInflector::class => \League\Tactician\Handler\MethodNameInflector\HandleInflector::class,
\Pheanstalk\Contract\PheanstalkInterface::class => \JCIT\jobqueue\components\Beanstalk::class,
\Pheanstalk\Contract\SocketFactoryInterface::class => function() {
return new \Pheanstalk\SocketFactory('localhost', 11300, 10);
},
]
],
public function actions(): array
{
return [
'daemon' => \JCIT\jobqueue\actions\DaemonAction::class,
];
}
class JobQueueController extends \yii\console\Controller
{
public $defaultAction = 'daemon';
public function actionTest(
\JCIT\jobqueue\interfaces\JobQueueInterface $jobQueue
) {
$task = \Yii::createObject(\JCIT\jobqueue\jobs\HelloJob::class, ['world']);
$jobQueue->putJob($task);
}
/**
* @return array
*/
public function actions(): array
{
return [
'daemon' => [
'class' => \JCIT\jobqueue\actions\DaemonAction::class,
]
];
}
}