36 lines
1012 B
PHP
36 lines
1012 B
PHP
<?php
|
|
|
|
namespace app\api\job;
|
|
|
|
use think\queue\Job;
|
|
use app\common\PromotionService;
|
|
|
|
class PromotionSend
|
|
{
|
|
public function fire(Job $job, $data)
|
|
{
|
|
$taskId = intval(isset($data['task_id']) ? $data['task_id'] : 0);
|
|
$service = new PromotionService();
|
|
|
|
if (!$taskId) {
|
|
$service->log('[PromotionSend] missing task_id, job deleted');
|
|
$job->delete();
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$result = $service->processNextEmail($taskId);
|
|
$service->log('[PromotionSend] task=' . $taskId . ' result=' . json_encode($result));
|
|
|
|
if (!empty($result['done'])) {
|
|
$reason = isset($result['reason']) ? $result['reason'] : '';
|
|
$service->log('[PromotionSend] task=' . $taskId . ' finished, reason=' . $reason);
|
|
}
|
|
} catch (\Exception $e) {
|
|
$service->log('[PromotionSend] task=' . $taskId . ' exception=' . $e->getMessage());
|
|
}
|
|
|
|
$job->delete();
|
|
}
|
|
}
|