mirror of
https://github.com/acepanel/panel.git
synced 2026-02-05 05:47:17 +08:00
特性:首次提交
This commit is contained in:
68
app/Jobs/ProcessShell.php
Normal file
68
app/Jobs/ProcessShell.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* 任务最大尝试次数
|
||||
* @var int
|
||||
*/
|
||||
public int $tries = 1;
|
||||
/**
|
||||
* 任务运行的超时时间
|
||||
* @var int
|
||||
*/
|
||||
public int $timeout = 7200;
|
||||
|
||||
/**
|
||||
* 任务名
|
||||
*/
|
||||
public string $task_id;
|
||||
|
||||
/**
|
||||
* 任务脚本
|
||||
*/
|
||||
public string $shell;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($task_id)
|
||||
{
|
||||
$this->task_id = $task_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
// 查询任务
|
||||
$task = Task::query()->where('id', $this->task_id)->get();
|
||||
echo $task->name . "开始执行".PHP_EOL;
|
||||
// 更新任务状态为running
|
||||
$task->job_id = $this->job->getJobId();
|
||||
$task->status = 'running';
|
||||
$task->save();
|
||||
//shell_exec($task->shell.' > '.$task->log.' 2>&1 &');
|
||||
// 更新任务状态
|
||||
$task->status = 'finished';
|
||||
$task->save();
|
||||
echo $task->name . "执行完毕".PHP_EOL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user