|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Abrouter\Client\DB\Managers; |
| 6 | + |
| 7 | +use Abrouter\Client\DB\Dictionary\ParallelRunningDictionary; |
| 8 | +use Abrouter\Client\DB\RedisConnection; |
| 9 | +use Abrouter\Client\DB\Repositories\ParallelRunningStateCachedRepository; |
| 10 | + |
| 11 | +class ParallelRunningStateManager |
| 12 | +{ |
| 13 | + private RedisConnection $redisConnection; |
| 14 | + |
| 15 | + private ParallelRunningStateCachedRepository $parallelRunningStateCachedRepository; |
| 16 | + |
| 17 | + public function __construct( |
| 18 | + RedisConnection $redisConnection, |
| 19 | + ParallelRunningStateCachedRepository $parallelRunningStateCachedRepository |
| 20 | + ) { |
| 21 | + $this->redisConnection = $redisConnection; |
| 22 | + $this->parallelRunningStateCachedRepository = $parallelRunningStateCachedRepository; |
| 23 | + } |
| 24 | + |
| 25 | + public function setReadyToServe() |
| 26 | + { |
| 27 | + $this->redisConnection->getConnection()->set( |
| 28 | + ParallelRunningDictionary::IS_RUNNING_KEY, |
| 29 | + ParallelRunningDictionary::IS_RUNNING_VALUE_TRUE |
| 30 | + ); |
| 31 | + $this->parallelRunningStateCachedRepository->clearCacheServing(); |
| 32 | + } |
| 33 | + |
| 34 | + public function setStopServing() |
| 35 | + { |
| 36 | + $this->redisConnection->getConnection()->set( |
| 37 | + ParallelRunningDictionary::IS_RUNNING_KEY, |
| 38 | + ParallelRunningDictionary::IS_RUNNING_VALUE_STOPPED |
| 39 | + ); |
| 40 | + $this->parallelRunningStateCachedRepository->clearCacheServing(); |
| 41 | + } |
| 42 | + |
| 43 | + public function setInitialized() |
| 44 | + { |
| 45 | + $this->redisConnection->getConnection()->set( |
| 46 | + ParallelRunningDictionary::IS_INITIAZLIED_KEY, |
| 47 | + ParallelRunningDictionary::IS_INITIAZLIED_TRUE_VALUE |
| 48 | + ); |
| 49 | + $this->parallelRunningStateCachedRepository->clearCacheInitialized(); |
| 50 | + } |
| 51 | +} |
0 commit comments