[更新]优化后台任务进程(去除中间执行文件)

This commit is contained in:
Anyon 2019-08-23 11:19:09 +08:00
parent 1b84a1519b
commit 5df85351c4
3 changed files with 3 additions and 11 deletions

View File

@ -57,13 +57,9 @@ class Listen extends Task
foreach (Db::name('SystemQueue')->where([['status', 'eq', '1'], ['time', '<=', time()]])->order('time asc')->select() as $item) {
try {
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()) {
$command = env('runtime_path') . "queue/{$item['id']}.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']} -";
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$this->cmd}";
}
if ($this->checkProcess()) {
$output->comment("处理任务的子进程已经存在 --> [{$item['id']}] {$item['title']}");

View File

@ -51,7 +51,6 @@ class Start extends Task
$this->setWinProcess();
$this->createProcess();
$this->setBaseProcess();
$output->writeln('正在检查异步任务监听主进程状态...');
sleep(1);
if (($pid = $this->checkProcess()) > 0) {
$output->info("异步任务监听主进程{$pid}启动成功!");
@ -69,10 +68,7 @@ class Start extends Task
private function setWinProcess()
{
if ($this->isWin()) {
$command = env('runtime_path') . "queue" . DIRECTORY_SEPARATOR . "listen.cmd";
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}";
$this->cmd = __DIR__ . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "process.exe {$this->bin} xtask:listen";
}
}
}