修改自动推广的相关任务
This commit is contained in:
@@ -1761,20 +1761,9 @@ class EmailClient extends Base
|
||||
$service = new PromotionService();
|
||||
$taskId = intval($data['id']);
|
||||
|
||||
// 调用前快照:用于解释"为什么没入队"
|
||||
$task = \think\Db::name('promotion_task')->where('task_id', $taskId)->find();
|
||||
$pending = \think\Db::name('promotion_email_log')
|
||||
->where('task_id', $taskId)
|
||||
->where('state', 0)
|
||||
->where('prepared_at', 0)
|
||||
->count();
|
||||
|
||||
$result = $service->dispatchPrepareEmails($taskId);
|
||||
|
||||
return jsonSuccess([
|
||||
'task_id' => $taskId,
|
||||
'task_state' => $task ? intval($task['state']) : null, // 0 才能 dispatch;5 已准备完
|
||||
'pending_before' => intval($pending), // 调用前还能入队的 log 数
|
||||
'dispatch_result' => $result, // ['dispatched' => N, ...]
|
||||
]);
|
||||
}
|
||||
@@ -1793,6 +1782,72 @@ class EmailClient extends Base
|
||||
return jsonSuccess($result);
|
||||
}
|
||||
|
||||
public function mytestqqq(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
"id"=>"require"
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$service = new PromotionService();
|
||||
$service->enqueuePrepareEmail(intval($data['id']));
|
||||
return jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* 队列写入测试:推一条 myTestQueue,并返回 push 返回值 + 与 queueDebug 相同 Redis 下的 LLEN(便于对照 redis-cli)。
|
||||
*/
|
||||
public function mytestQueue()
|
||||
{
|
||||
$queueName = 'myTestQueue';
|
||||
$jobClass = 'app\\api\\job\\myQueue@fire';
|
||||
$data = ['testData' => 1];
|
||||
|
||||
$cfg = Config::get('queue');
|
||||
$connector = isset($cfg['connector']) ? (string)$cfg['connector'] : '';
|
||||
if (stripos($connector, 'sync') !== false) {
|
||||
return jsonError('queue connector is Sync — will not write Redis. Check application/extra/queue.php');
|
||||
}
|
||||
if (!extension_loaded('redis')) {
|
||||
return jsonError('PHP redis extension not loaded — Queue Redis connector cannot run.');
|
||||
}
|
||||
|
||||
try {
|
||||
$jobId = Queue::push($jobClass, $data, $queueName);
|
||||
} catch (\Throwable $e) {
|
||||
return jsonError('Queue::push failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// 独立连一次 Redis,确认与 PHP-FPM 使用的配置一致且 LIST 长度(避免「以为写了其实没有」)
|
||||
$verify = ['ready_len' => null, 'error' => null];
|
||||
try {
|
||||
$redis = new \Redis();
|
||||
$connectMethod = !empty($cfg['persistent']) ? 'pconnect' : 'connect';
|
||||
$redis->$connectMethod($cfg['host'] ?? '127.0.0.1', $cfg['port'] ?? 6379);
|
||||
if (!empty($cfg['password'])) {
|
||||
$redis->auth($cfg['password']);
|
||||
}
|
||||
$redis->select($cfg['select'] ?? 0);
|
||||
$readyKey = 'queues:' . $queueName;
|
||||
$verify['ready_len'] = (int)$redis->lLen($readyKey);
|
||||
$verify['exists'] = (bool)$redis->exists($readyKey);
|
||||
$verify['ping'] = (string)$redis->ping();
|
||||
$verify['checked_db'] = (int)($cfg['select'] ?? 0);
|
||||
$verify['checked_host'] = (string)($cfg['host'] ?? '127.0.0.1');
|
||||
$verify['checked_port'] = (int)($cfg['port'] ?? 6379);
|
||||
} catch (\Throwable $e) {
|
||||
$verify['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return jsonSuccess([
|
||||
'job_id' => $jobId,
|
||||
'queue' => $queueName,
|
||||
'connector' => $connector,
|
||||
'after_push' => $verify,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 队列调试:查看 Redis 里队列长度(不依赖 redis-cli)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user