46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Job;
|
|
|
|
use Hyperf\AsyncQueue\Job;
|
|
use App\Model\Attachment as aModel;
|
|
use App\Model\Post as pModel;
|
|
|
|
class FileExportJob extends Job
|
|
{
|
|
protected int $maxAttempts = 1;
|
|
protected int $attachmentId;
|
|
|
|
public function __construct(array $params)
|
|
{
|
|
$this->attachmentId = $params['attachmentId'];
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
try {
|
|
$attach = aModel::find($this->attachmentId);
|
|
if (empty($attach)) return false;
|
|
switch ($attach->module) {
|
|
case "post_export":
|
|
$res = pModel::exportData($attach->params);
|
|
$res = true;
|
|
break;
|
|
default:
|
|
throw new \Exception("导出模块不存在");
|
|
}
|
|
aModel::edit([
|
|
'attachment_id' => $this->attachmentId,
|
|
'status' => $res ? 1 : 2,
|
|
'fail_reason' => $res ? "" : "导出失败"
|
|
]);
|
|
} catch (\Exception $e) {
|
|
aModel::edit([
|
|
'attachment_id' => $this->attachmentId,
|
|
'status' => 2,
|
|
'fail_reason' => $e->getMessage()
|
|
]);
|
|
}
|
|
return true;
|
|
}
|
|
} |