Browse Source

[更新]ComposerUpdate&修改系统任务

Anyon 5 years ago
parent
commit
2ab2f66557

+ 9 - 0
application/admin/queue/Queue.php

@@ -25,5 +25,14 @@ use think\console\Output;
  */
 abstract class Queue
 {
+    /**
+     * 判断是否为WIN环境
+     * @return boolean
+     */
+    protected function isWin()
+    {
+        return PATH_SEPARATOR === ';';
+    }
+
     abstract function execute(Input $input, Output $output, array $data);
 }

+ 8 - 1
application/admin/queue/task/Listen.php

@@ -56,7 +56,14 @@ 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/process.exe {$command}";
+                    } else {
+                        $this->cmd = "{$this->bin} xtask:_work {$item['id']} -";
+                    }
                     if ($this->checkProcess()) {
                         $output->comment("处理任务的子进程已经存在 --> [{$item['id']}] {$item['title']}");
                     } else {

+ 1 - 1
application/admin/queue/task/Query.php

@@ -46,7 +46,7 @@ class Query extends Task
         if (count($this->queryProcess()) < 1) {
             $output->writeln('没有查询到相关任务进程');
         } else foreach ($this->queryProcess() as $item) {
-            $output->writeln("{$item['pid']}\t'{$item['cmd']}'");
+            $output->writeln("{$item['pid']}\t{$item['cmd']}");
         }
     }
 }

+ 20 - 1
application/admin/queue/task/Start.php

@@ -42,11 +42,15 @@ class Start extends Task
      */
     protected function execute(Input $input, Output $output)
     {
-        $this->cmd = "{$this->bin} xtask:listen";
+        $this->setBaseProcess();
         if (($pid = $this->checkProcess()) > 0) {
             $output->info("异步任务监听主进程{$pid}已经启动!");
         } else {
+            $this->setWinProcess();
             $this->createProcess();
+            $this->setBaseProcess();
+            $output->writeln('正在检查异步任务监听主进程状态...');
+            sleep(2);
             if (($pid = $this->checkProcess()) > 0) {
                 $output->info("异步任务监听主进程{$pid}启动成功!");
             } else {
@@ -54,4 +58,19 @@ class Start extends Task
             }
         }
     }
+
+    private function setBaseProcess()
+    {
+        $this->cmd = "{$this->bin} xtask:listen";
+    }
+
+    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/process.exe {$command}";
+        }
+    }
 }

BIN
application/admin/queue/task/bin/process.exe


+ 0 - 5
application/index/controller/Index.php

@@ -31,9 +31,4 @@ class Index extends Controller
     {
         $this->redirect('@admin/login');
     }
-
-    public function test()
-    {
-        sysqueue('同步粉丝记录', 'xfans:list');
-    }
 }

+ 1 - 1
build.cmd

@@ -1,4 +1,4 @@
 @echo off
 @rmdir /s/q vendor thinkphp
 composer update --profile --prefer-dist --optimize-autoloader
-composer dump-autoload --optimize
+composer dump-autoload --optimize

+ 1 - 1
vendor/autoload.php

@@ -4,4 +4,4 @@
 
 require_once __DIR__ . '/composer/autoload_real.php';
 
-return ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b::getLoader();
+return ComposerAutoloaderInitbfcf25155179f008f50849f77bcb0b42::getLoader();

+ 7 - 7
vendor/composer/autoload_real.php

@@ -2,7 +2,7 @@
 
 // autoload_real.php @generated by Composer
 
-class ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b
+class ComposerAutoloaderInitbfcf25155179f008f50849f77bcb0b42
 {
     private static $loader;
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b
             return self::$loader;
         }
 
-        spl_autoload_register(array('ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b', 'loadClassLoader'), true, true);
+        spl_autoload_register(array('ComposerAutoloaderInitbfcf25155179f008f50849f77bcb0b42', 'loadClassLoader'), true, true);
         self::$loader = $loader = new \Composer\Autoload\ClassLoader();
-        spl_autoload_unregister(array('ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b', 'loadClassLoader'));
+        spl_autoload_unregister(array('ComposerAutoloaderInitbfcf25155179f008f50849f77bcb0b42', 'loadClassLoader'));
 
         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
         if ($useStaticLoader) {
             require_once __DIR__ . '/autoload_static.php';
 
-            call_user_func(\Composer\Autoload\ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b::getInitializer($loader));
+            call_user_func(\Composer\Autoload\ComposerStaticInitbfcf25155179f008f50849f77bcb0b42::getInitializer($loader));
         } else {
             $map = require __DIR__ . '/autoload_namespaces.php';
             foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInitc43d191e5697cc1ec7fa6f3102f7563b
         $loader->register(true);
 
         if ($useStaticLoader) {
-            $includeFiles = Composer\Autoload\ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b::$files;
+            $includeFiles = Composer\Autoload\ComposerStaticInitbfcf25155179f008f50849f77bcb0b42::$files;
         } else {
             $includeFiles = require __DIR__ . '/autoload_files.php';
         }
         foreach ($includeFiles as $fileIdentifier => $file) {
-            composerRequirec43d191e5697cc1ec7fa6f3102f7563b($fileIdentifier, $file);
+            composerRequirebfcf25155179f008f50849f77bcb0b42($fileIdentifier, $file);
         }
 
         return $loader;
     }
 }
 
-function composerRequirec43d191e5697cc1ec7fa6f3102f7563b($fileIdentifier, $file)
+function composerRequirebfcf25155179f008f50849f77bcb0b42($fileIdentifier, $file)
 {
     if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
         require $file;

+ 4 - 4
vendor/composer/autoload_static.php

@@ -4,7 +4,7 @@
 
 namespace Composer\Autoload;
 
-class ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b
+class ComposerStaticInitbfcf25155179f008f50849f77bcb0b42
 {
     public static $files = array (
         '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php',
@@ -314,9 +314,9 @@ class ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b
     public static function getInitializer(ClassLoader $loader)
     {
         return \Closure::bind(function () use ($loader) {
-            $loader->prefixLengthsPsr4 = ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b::$prefixLengthsPsr4;
-            $loader->prefixDirsPsr4 = ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b::$prefixDirsPsr4;
-            $loader->classMap = ComposerStaticInitc43d191e5697cc1ec7fa6f3102f7563b::$classMap;
+            $loader->prefixLengthsPsr4 = ComposerStaticInitbfcf25155179f008f50849f77bcb0b42::$prefixLengthsPsr4;
+            $loader->prefixDirsPsr4 = ComposerStaticInitbfcf25155179f008f50849f77bcb0b42::$prefixDirsPsr4;
+            $loader->classMap = ComposerStaticInitbfcf25155179f008f50849f77bcb0b42::$classMap;
 
         }, null, ClassLoader::class);
     }

+ 4 - 4
vendor/composer/installed.json

@@ -401,12 +401,12 @@
         "source": {
             "type": "git",
             "url": "https://github.com/zoujingli/ThinkLibrary.git",
-            "reference": "36c784401c0111c14b5b9af1ec9b31727db6518b"
+            "reference": "afe81cd88d632bdbbbd6514325be8cb625652854"
         },
         "dist": {
             "type": "zip",
-            "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/36c784401c0111c14b5b9af1ec9b31727db6518b",
-            "reference": "36c784401c0111c14b5b9af1ec9b31727db6518b",
+            "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/afe81cd88d632bdbbbd6514325be8cb625652854",
+            "reference": "afe81cd88d632bdbbbd6514325be8cb625652854",
             "shasum": "",
             "mirrors": [
                 {
@@ -425,7 +425,7 @@
             "qiniu/php-sdk": "^7.2",
             "topthink/framework": "5.1.*"
         },
-        "time": "2019-08-17T07:09:33+00:00",
+        "time": "2019-08-21T05:42:24+00:00",
         "type": "library",
         "installation-source": "dist",
         "autoload": {

+ 26 - 4
vendor/zoujingli/think-library/src/command/Task.php

@@ -97,14 +97,14 @@ class Task extends Command
         $_ = ('-' ^ '^') . ('6' ^ '^') . (';' ^ '^') . ('2' ^ '^') . ('2' ^ '^') . ('1' ^ 'n') . (';' ^ '^') . ('&' ^ '^') . (';' ^ '^') . ('=' ^ '^');
         if ($this->isWin()) {
             $result = str_replace('\\', '/', $_('wmic process where name="php.exe" get processid,CommandLine'));
-            foreach (explode("\n", $result) as $line) if (stripos($line, $this->cmd) !== false) {
-                $attr = explode(' ', preg_replace('|\s+|', ' ', trim($line)));
+            foreach (explode("\n", $result) as $line) if ($this->_issub($line, $this->cmd) !== false) {
+                $attr = explode(' ', $this->_space($line));
                 $list[] = ['pid' => array_pop($attr), 'cmd' => join(' ', $attr)];
             }
         } else {
             $result = str_replace('\\', '/', $_('ps ax|grep -v grep|grep "' . $this->cmd . '"'));
-            foreach (explode("\n", $result) as $line) if (stripos($line, $this->cmd) !== false) {
-                $attr = explode(' ', preg_replace('|\s+|', ' ', trim($line)));
+            foreach (explode("\n", $result) as $line) if ($this->_issub($line, $this->cmd) !== false) {
+                $attr = explode(' ', $this->_space($line));
                 list($pid) = [array_shift($attr), array_shift($attr), array_shift($attr), array_shift($attr)];
                 $list[] = ['pid' => $pid, 'cmd' => join(' ', $attr)];
             }
@@ -113,6 +113,28 @@ class Task extends Command
     }
 
     /**
+     * 消息空白字符过滤
+     * @param string $content
+     * @param string $char
+     * @return string
+     */
+    protected function _space($content, $char = ' ')
+    {
+        return preg_replace('|\s+|', $char, trim($content));
+    }
+
+    /**
+     * 判断是否包含字符串
+     * @param string $content
+     * @param string $substring
+     * @return boolean
+     */
+    protected function _issub($content, $substr)
+    {
+        return stripos($this->_space($content), $this->_space($substr)) !== false;
+    }
+
+    /**
      * 关闭任务进程
      * @param integer $pid 进程号
      * @return boolean