2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 17:17:13 +08:00

特性:调整任务队列与取消API限流

This commit is contained in:
耗子
2022-12-01 00:16:20 +08:00
parent 329f58da4b
commit 36b80c4b6f
3 changed files with 22 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
use App\Models\Plugin;
use App\Models\Setting;
use App\Models\Task;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
@@ -52,6 +53,9 @@ class Panel extends Command
case 'writeMysqlPassword':
$this->writeMysqlPassword();
break;
case 'cleanRunningTask':
$this->cleanRunningTask();
break;
default:
$this->error('错误的操作');
break;
@@ -192,4 +196,13 @@ class Panel extends Command
Setting::query()->where('name', 'mysql_root_password')->update(['value' => $password]);
$this->info('成功');
}
/**
* 清理所有运行中的任务
*/
private function cleanRunningTask(): void
{
Task::query()->where('status', 'running')->update(['status' => 'finished']);
$this->info('成功');
}
}

View File

@@ -41,7 +41,6 @@ class Kernel extends HttpKernel
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

View File

@@ -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;
}
}