This commit is contained in:
jhx
2023-08-18 11:34:03 +08:00
commit b0d4767e22
20 changed files with 1366 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
/**
*
* @date 2021/6/24 16:40
*/
namespace Tests;
class TestHandler extends \WorkerManQueue\Handler\JobHandler
{
/**
* 失败回调方法
* @param \WorkerManQueue\Job $job 任务
* @param string $func 执行的方法
* @param array $data 参数
* @return mixed
*/
public function failed(\WorkerManQueue\Job $job, $func, $data)
{
\WorkerManQueue\Helpers\Log::info('failed run handler -- func: ' . $func . ' -- params: ' . json_encode($data));
}
/**
* 任务成功回调
* @param \WorkerManQueue\Job $job 任务
* @param string $func 执行的方法
* @param array $data 参数
* @return mixed
*/
public function success(\WorkerManQueue\Job $job, $func, $data)
{
\WorkerManQueue\Helpers\Log::info('success run handler -- func: ' . $func . ' -- params: ' . json_encode($data));
}
public function test(\WorkerManQueue\Job $job, $data)
{
$res = 'success';
\WorkerManQueue\Helpers\Log::info('run handler -- func: test -- params: ' . json_encode($data) . '; result : ' . var_export($res, true));
}
}
+2
View File
@@ -0,0 +1,2 @@
<?php
require dirname(__DIR__)."/vendor/autoload.php";
+24
View File
@@ -0,0 +1,24 @@
<?php
return [
'log' => [
'logRoot' => __DIR__ . '/../runtime/log',
'fileName' => '\q\u\e\u\e_Y-m-d.\l\o\g',
],
'connectList' => [
'Redis' => [
'class' => '\\WorkerManQueue\\Connection\\Redis\\Redis',
'config' => [
'popTimeout' => 3, // pop阻塞的超时时长 s
'host' => '127.0.0.1', // 数据库地址
'port' => 6379, // 数据库端口
'db' => 0, // 库
'password' => null, // 密码
'connTimeout' => 1, // 链接超时
],
]
],
'currentConnect' => 'Redis',
];
+13
View File
@@ -0,0 +1,13 @@
<?php
require __DIR__ . "/bootstrap.php";
require __DIR__ . "/TestHandler.php";
$config = include __DIR__ . '/config.php';
$queue = \WorkerManQueue\Queue::getInstance('Redis', $config);
use Tests\TestHandler;
for ($i = 0; $i <= 100; $i++) {
$r = $queue->pushOn(new TestHandler(), 'test', ['test' => $i], 'queue');
}
+9
View File
@@ -0,0 +1,9 @@
<?php
require __DIR__."/bootstrap.php";
$config = include __DIR__.'/config.php';
$worker = new \WorkerManQueue\Worker($config);
$worker->run();