diff --git a/app/Console/Commands/RequestFetcher.php b/app/Console/Commands/RequestFetcher.php index f932b92b0339f5ec9d85d6e24ddfacd23af53372..f6305c3916520f79d6f852caba73e9656a58d6c0 100644 --- a/app/Console/Commands/RequestFetcher.php +++ b/app/Console/Commands/RequestFetcher.php @@ -50,10 +50,17 @@ class RequestFetcher extends Command */ public function handle() { + $pidFile = "/tmp/fetcher"; pcntl_signal(SIGINT, [$this, "sig_handler"]); pcntl_signal(SIGTERM, [$this, "sig_handler"]); pcntl_signal(SIGHUP, [$this, "sig_handler"]); + touch($pidFile); + + if (!file_exists($pidFile)) { + return; + } + try { $blocking = false; $redis = Redis::connection("cache"); @@ -108,9 +115,8 @@ class RequestFetcher extends Command usleep(50 * 1000); } } - } catch (\Exception $e) { - Log::error($e->getMessage()); } finally { + unlink($pidFile); curl_multi_close($this->multicurl); } } diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index f65ea5f47148e9fb7c3b2eda03c3f78880d43501..977aee9cdf9f312e550c5dddb16818d063168aff 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -141,4 +141,18 @@ spec: command: ["su"] args: ["-s", "/bin/sh", "-c", "php artisan requests:fetcher", "nginx"] imagePullPolicy: {{ .Values.image.pullPolicy }} + livenessProbe: + exec: + command: + - cat + - /tmp/fetcher + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + exec: + command: + - cat + - /tmp/fetcher + initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} {{- end -}}