mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 23:27:17 +08:00
特性:调整任务队列与取消API限流
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Task;
|
||||
|
||||
class ProcessShell implements ShouldQueue, ShouldBeUnique
|
||||
class ProcessShell implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
@@ -52,9 +51,15 @@ class ProcessShell implements ShouldQueue, ShouldBeUnique
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
// 检查当前是否有任务正在运行
|
||||
$taskCheck = Task::query()->where('status', 'running')->get();
|
||||
if ($taskCheck->isNotEmpty()) {
|
||||
$this->release(10);
|
||||
return;
|
||||
}
|
||||
// 查询任务
|
||||
$task = Task::query()->where('id', $this->task_id)->first();
|
||||
echo $task->name . "开始执行".PHP_EOL;
|
||||
echo $task->name."开始执行".PHP_EOL;
|
||||
// 更新任务状态为running
|
||||
$task->job_id = $this->job->getJobId();
|
||||
$task->status = 'running';
|
||||
@@ -63,6 +68,6 @@ class ProcessShell implements ShouldQueue, ShouldBeUnique
|
||||
// 更新任务状态
|
||||
$task->status = 'finished';
|
||||
$task->save();
|
||||
echo $task->name . "执行完毕".PHP_EOL;
|
||||
echo $task->name."执行完毕".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user