|
5 | 5 | use Barryvdh\Queue\Models\Job; |
6 | 6 | use Illuminate\Queue\Queue; |
7 | 7 | use Illuminate\Queue\QueueInterface; |
| 8 | +use SebastianBergmann\Environment\Runtime; |
8 | 9 | use Symfony\Component\Process\Process; |
9 | 10 |
|
10 | 11 | class AsyncQueue extends Queue implements QueueInterface |
@@ -59,18 +60,45 @@ public function storeJob($job, $data, $delay = 0) |
59 | 60 | */ |
60 | 61 | public function startProcess($jobId) |
61 | 62 | { |
62 | | - $environment = $this->container->environment(); |
| 63 | + $command = $this->getCommand(); |
63 | 64 | $cwd = $this->container['path.base']; |
64 | | - $string = 'php artisan queue:async %d --env=%s '; |
| 65 | + |
| 66 | + $process = new Process($command, $cwd); |
| 67 | + $process->run(); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get the Artisan command as a string for the job id. |
| 72 | + * |
| 73 | + * @param int $jobId |
| 74 | + * |
| 75 | + * @return string |
| 76 | + */ |
| 77 | + protected function getCommand($jobId) |
| 78 | + { |
| 79 | + $string = $this->getBinary().' artisan queue:async %d --env=%s '; |
| 80 | + |
65 | 81 | if (defined('PHP_WINDOWS_VERSION_BUILD')) { |
66 | 82 | $string = 'start /B '.$string.' > NUL'; |
67 | 83 | } else { |
68 | 84 | $string = 'nohup '.$string.' > /dev/null 2>&1 &'; |
69 | 85 | } |
70 | 86 |
|
71 | | - $command = sprintf($string, $jobId, $environment); |
72 | | - $process = new Process($command, $cwd); |
73 | | - $process->run(); |
| 87 | + $environment = $this->container->environment(); |
| 88 | + |
| 89 | + return sprintf($string, $jobId, $environment); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Get the php binary path. |
| 94 | + * |
| 95 | + * @return string |
| 96 | + */ |
| 97 | + protected function getBinary() |
| 98 | + { |
| 99 | + $runtime = new Runtime(); |
| 100 | + |
| 101 | + return $runtime->getBinary(); |
74 | 102 | } |
75 | 103 |
|
76 | 104 | /** |
|
0 commit comments