Commit 948afe28 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

request fetcher now waits for fpm to stop before shutting down

parent 9602eb01
......@@ -2,10 +2,13 @@
namespace App\Console\Commands;
use ErrorException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
class FPMGracefulStop extends Command
{
const REDIS_FPM_STOPPED_KEY = "fpm_stopped";
/**
* The name and signature of the console command.
*
......@@ -33,6 +36,11 @@ class FPMGracefulStop extends Command
} while ($active_fpm_processes === null || $active_fpm_processes > 1);
$this->info("Only one FPM process left. Ready to stop fpm...");
// The Request fetcher won't stop before FPM is not stopped with processing requests
// because there could be last jobs flying in
// This Redis Value will tell him that it's good to stop
Redis::set(self::REDIS_FPM_STOPPED_KEY, "true");
$this->info("Set Redis Key");
return 0;
}
......@@ -51,8 +59,12 @@ class FPMGracefulStop extends Command
"header" => "Authorization: Basic $auth",
],
]);
$fpm_info = \file_get_contents($url, false, $context);
try {
$fpm_info = \file_get_contents($url, false, $context);
} catch (ErrorException $e) {
// Webserver could not be reached. Probably already shut down so there are no active connections anyways
return 0;
}
if ($fpm_info !== false) {
$fpm_info = \json_decode($fpm_info);
} else {
......
......@@ -84,7 +84,8 @@ class RequestFetcher extends Command
if ($newJobs === 0 && $answersRead === 0) {
usleep(10 * 1000);
}
if (!$this->shouldRun && $operationsRunning === 0) {
if (!$this->shouldRun && $operationsRunning === 0 && Redis::get(FPMGracefulStop::REDIS_FPM_STOPPED_KEY) !== NULL) {
break;
}
}
......@@ -234,8 +235,7 @@ class RequestFetcher extends Command
public function sig_handler($sig)
{
$this->info("Received Shutdown signal");
$this->shouldRun = false;
echo ("Terminating Process\n");
$this->info("Terminating Process\n");
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment