Stop.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\queue\task;
  15. use library\command\Task;
  16. use think\console\Input;
  17. use think\console\Output;
  18. /**
  19. * 平滑停止异步任务守护的主进程
  20. * Class Stop
  21. * @package app\admin\queue\task
  22. */
  23. class Stop extends Task
  24. {
  25. /**
  26. * 指令属性配置
  27. */
  28. protected function configure()
  29. {
  30. $this->setName('xtask:stop')->setDescription('[控制]平滑停止所有的异步任务进程');
  31. }
  32. /**
  33. * 停止所有任务执行
  34. * @param Input $input
  35. * @param Output $output
  36. */
  37. protected function execute(Input $input, Output $output)
  38. {
  39. $this->cmd = "{$this->bin} xtask:";
  40. if (count($processList = $this->queryProcess()) < 1) {
  41. $output->writeln("没有需要结束的任务进程哦!");
  42. } else foreach ($processList as $item) {
  43. $this->closeProcess($item['pid']);
  44. $output->writeln("发送结束任务进程{$item['pid']}指令成功!");
  45. }
  46. }
  47. }