修改自动推广的相关任务
This commit is contained in:
@@ -4,7 +4,6 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\ExpertFinderService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 专家抓取队列任务。
|
||||
@@ -16,25 +15,16 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class FetchExperts
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$field = isset($data['field']) ? (string)$data['field'] : '';
|
||||
if ($field === '') {
|
||||
$this->oQueueJob->log("FetchExperts 无效的 field,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$service = new ExpertFinderService();
|
||||
$service->doFetchForField(
|
||||
$field,
|
||||
@@ -42,14 +32,6 @@ class FetchExperts
|
||||
isset($data['per_page']) ? intval($data['per_page']) : 100,
|
||||
isset($data['min_year']) ? $data['min_year'] : null
|
||||
);
|
||||
$this->oQueueJob->log("FetchExperts 完成 | field={$field}");
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "field={$field}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "field={$field}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\ExpertFinderService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 队列任务:用本地大模型从 affiliation 推断国家,写入 expert.country_id / country。
|
||||
@@ -17,16 +16,9 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class FillExpertCountry
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
|
||||
$affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : '';
|
||||
@@ -35,7 +27,6 @@ class FillExpertCountry
|
||||
|
||||
$service = new ExpertFinderService();
|
||||
|
||||
try {
|
||||
if ($expertId && $affiliation !== '') {
|
||||
$service->fillExpertCountry($expertId, $affiliation, $chatUrl);
|
||||
}
|
||||
@@ -43,12 +34,5 @@ class FillExpertCountry
|
||||
|
||||
// 链式:处理完当前专家立刻拉下一个进来
|
||||
$service->enqueueNextCountryFill(1, $queue, $chatUrl);
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "expert_id={$expertId} queue={$queue}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "expert_id={$expertId} queue={$queue}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\PromotionService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 【已废弃 / 兼容保留】
|
||||
@@ -16,35 +15,17 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class PromotionPrepare
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$taskId = isset($data['task_id']) ? intval($data['task_id']) : 0;
|
||||
if ($taskId <= 0) {
|
||||
$this->oQueueJob->log("PromotionPrepare[deprecated] 无效的 task_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$service = new PromotionService();
|
||||
$service->enqueuePrepareTask($taskId);
|
||||
$this->oQueueJob->log("PromotionPrepare[deprecated] forwarded task_id={$taskId} -> PromotionPrepareTask");
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "[deprecated] task_id={$taskId}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "[deprecated] task_id={$taskId}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\PromotionService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 队列任务:单封邮件 prepare(调用 LLM 生成个性化描述 + 渲染模板 + 写入 log)。
|
||||
@@ -18,41 +17,13 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class PromotionPrepareEmail
|
||||
{
|
||||
// private $oQueueJob;
|
||||
|
||||
// public function __construct()
|
||||
// {
|
||||
// $this->oQueueJob = new QueueJob();
|
||||
// }
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
// $this->oQueueJob->init($job);
|
||||
//
|
||||
$logId = isset($data['log_id']) ? intval($data['log_id']) : 0;
|
||||
// if ($logId <= 0) {
|
||||
// $this->oQueueJob->log("PromotionPrepareEmail 无效的 log_id,删除任务");
|
||||
// $job->delete();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
$service = new PromotionService();
|
||||
$service->log("id:".$logId);
|
||||
// $result = $service->prepareSingleEmail($logId);
|
||||
//
|
||||
// $code = isset($result['code']) ? $result['code'] : '';
|
||||
// $msg = isset($result['msg']) ? $result['msg'] : '';
|
||||
// $llm = isset($result['llm_status']) ? $result['llm_status'] : '';
|
||||
// $this->oQueueJob->log("PromotionPrepareEmail 完成 | log_id={$logId} code={$code} llm_status={$llm} msg={$msg}");
|
||||
|
||||
$result = $service->prepareSingleEmail($logId);
|
||||
$job->delete();
|
||||
// } catch (\Exception $e) {
|
||||
// $this->oQueueJob->handleException($e, $job, "log_id={$logId}");
|
||||
// } catch (\Throwable $e) {
|
||||
// $this->oQueueJob->handleException($e, $job, "log_id={$logId}");
|
||||
// } finally {
|
||||
// $this->oQueueJob->finnal();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,40 +17,17 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class PromotionPrepareTask
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$taskId = isset($data['task_id']) ? intval($data['task_id']) : 0;
|
||||
if ($taskId <= 0) {
|
||||
$this->oQueueJob->log("PromotionPrepareTask 无效的 task_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$service = new PromotionService();
|
||||
$result = $service->dispatchPrepareEmails($taskId);
|
||||
|
||||
$dispatched = isset($result['dispatched']) ? $result['dispatched'] : 0;
|
||||
$alreadyDone = isset($result['already_done']) ? $result['already_done'] : 0;
|
||||
$err = isset($result['error']) ? $result['error'] : '';
|
||||
$this->oQueueJob->log("PromotionPrepareTask 完成 | task_id={$taskId} dispatched={$dispatched} already_done={$alreadyDone} error={$err}");
|
||||
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\PromotionService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 队列任务:发送 task 下"已 prepare"的邮件,按 min/max_interval 控制节奏。
|
||||
@@ -16,39 +15,18 @@ use app\common\QueueJob;
|
||||
*/
|
||||
class PromotionSend
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$taskId = isset($data['task_id']) ? intval($data['task_id']) : 0;
|
||||
if ($taskId <= 0) {
|
||||
$this->oQueueJob->log("PromotionSend 无效的 task_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$service = new PromotionService();
|
||||
$result = $service->processNextEmail($taskId);
|
||||
|
||||
$done = !empty($result['done']) ? 1 : 0;
|
||||
$reason = isset($result['reason']) ? $result['reason'] : '';
|
||||
$this->oQueueJob->log("PromotionSend 完成 | task_id={$taskId} done={$done} reason={$reason}");
|
||||
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
application/api/job/myQueue.php
Normal file
31
application/api/job/myQueue.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
class myQueue
|
||||
{
|
||||
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
try {
|
||||
// 你的业务逻辑(哪怕是空的)
|
||||
// 这里写任何代码
|
||||
|
||||
// 执行成功,删除任务
|
||||
$job->delete();
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// 如果你不想重试,直接删除
|
||||
$job->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:任务失败时执行
|
||||
public function failed($data)
|
||||
{
|
||||
// 失败后不做处理,直接跳过
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user