mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]优化后台任务进程(去除中间执行文件)
This commit is contained in:
parent
1b84a1519b
commit
5df85351c4
@ -57,13 +57,9 @@ class Listen extends Task
|
|||||||
foreach (Db::name('SystemQueue')->where([['status', 'eq', '1'], ['time', '<=', time()]])->order('time asc')->select() as $item) {
|
foreach (Db::name('SystemQueue')->where([['status', 'eq', '1'], ['time', '<=', time()]])->order('time asc')->select() as $item) {
|
||||||
try {
|
try {
|
||||||
Db::name('SystemQueue')->where(['id' => $item['id']])->update(['status' => '2', 'start_at' => date('Y-m-d H:i:s')]);
|
Db::name('SystemQueue')->where(['id' => $item['id']])->update(['status' => '2', 'start_at' => date('Y-m-d H:i:s')]);
|
||||||
|
$this->cmd = "{$this->bin} xtask:_work {$item['id']} -";
|
||||||
if ($this->isWin()) {
|
if ($this->isWin()) {
|
||||||
$command = env('runtime_path') . "queue/{$item['id']}.cmd";
|
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$this->cmd}";
|
||||||
file_exists(dirname($command)) or mkdir(dirname($command), 0755, true);
|
|
||||||
file_put_contents($command, "{$this->bin} xtask:_work {$item['id']} -" . PHP_EOL . 'del %~dp0%0 /y');
|
|
||||||
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$command}";
|
|
||||||
} else {
|
|
||||||
$this->cmd = "{$this->bin} xtask:_work {$item['id']} -";
|
|
||||||
}
|
}
|
||||||
if ($this->checkProcess()) {
|
if ($this->checkProcess()) {
|
||||||
$output->comment("处理任务的子进程已经存在 --> [{$item['id']}] {$item['title']}");
|
$output->comment("处理任务的子进程已经存在 --> [{$item['id']}] {$item['title']}");
|
||||||
|
@ -51,7 +51,6 @@ class Start extends Task
|
|||||||
$this->setWinProcess();
|
$this->setWinProcess();
|
||||||
$this->createProcess();
|
$this->createProcess();
|
||||||
$this->setBaseProcess();
|
$this->setBaseProcess();
|
||||||
$output->writeln('正在检查异步任务监听主进程状态...');
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
if (($pid = $this->checkProcess()) > 0) {
|
if (($pid = $this->checkProcess()) > 0) {
|
||||||
$output->info("异步任务监听主进程{$pid}启动成功!");
|
$output->info("异步任务监听主进程{$pid}启动成功!");
|
||||||
@ -69,10 +68,7 @@ class Start extends Task
|
|||||||
private function setWinProcess()
|
private function setWinProcess()
|
||||||
{
|
{
|
||||||
if ($this->isWin()) {
|
if ($this->isWin()) {
|
||||||
$command = env('runtime_path') . "queue" . DIRECTORY_SEPARATOR . "listen.cmd";
|
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$this->bin} xtask:listen";
|
||||||
file_exists(dirname($command)) or mkdir(dirname($command), 0755, true);
|
|
||||||
file_put_contents($command, $this->cmd . PHP_EOL . 'del %~dp0%0 /y');
|
|
||||||
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$command}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user