Created
June 28, 2014 18:00
-
-
Save reshadman/d178d05f874e2ef6a40d to your computer and use it in GitHub Desktop.
Worker long running daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function daemon($connectionName, $queue = null, $delay = 0, $memory = 128, $sleep = 3, $maxTries = 0) | |
{ | |
$lastRestart = $this->getTimestampOfLastQueueRestart(); | |
while (true) | |
{ | |
if ($this->daemonShouldRun()) | |
{ | |
$this->runNextJobForDaemon( | |
$connectionName, $queue, $delay, $sleep, $maxTries | |
); | |
} | |
else | |
{ | |
$this->sleep($sleep); | |
} | |
if ($this->memoryExceeded($memory) || $this->queueShouldRestart($lastRestart)) | |
{ | |
exec('php artisan queue:work --daemon > /dev/null 2>&1 &'); | |
$this->stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment