init admin
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use Webman\RedisQueue\Consumer;
|
||||
/**
|
||||
* 延迟写入日志sql
|
||||
*/
|
||||
class Sql implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'Sql';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
if(isset($data['model'])){
|
||||
switch($data['model']){
|
||||
case "RecordModel":
|
||||
unset($data['model']);
|
||||
\app\model\Record::create($data);
|
||||
break;
|
||||
case "RecordModel12":
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// 无需反序列化
|
||||
//var_export($data); // 输出 ['to' => 'tom@gmail.com', 'content' => 'hello']
|
||||
}
|
||||
// 消费失败回调
|
||||
/*
|
||||
$package = [
|
||||
'id' => 1357277951, // 消息ID
|
||||
'time' => 1709170510, // 消息时间
|
||||
'delay' => 0, // 延迟时间
|
||||
'attempts' => 2, // 消费次数
|
||||
'queue' => 'send-mail', // 队列名
|
||||
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||
'max_attempts' => 5, // 最大重试次数
|
||||
'error' => '错误信息' // 错误信息
|
||||
]
|
||||
*/
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
if($package['attempts'] >= $package['max_attempts']){
|
||||
\support\Log::error(json_encode($package['data']));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user