Can't reconnect to Redis, and it randomly dies... ugh

The pattern of unsubscribe/subscribe seems to segfault, as do reconnect,
etc. This Redis plugin isn't durable.
This commit is contained in:
Brandon Thomas
2021-02-18 04:31:40 -05:00
parent 89ecad04fe
commit 8c5537c33d
2 changed files with 14 additions and 0 deletions
@@ -34,6 +34,7 @@ void AEventSourceActor::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "BeginPlay() - 2");
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()")); UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()"));
if (redis == nullptr) { if (redis == nullptr) {
@@ -55,6 +56,16 @@ void AEventSourceActor::BeginDestroy()
void AEventSourceActor::Tick(float DeltaTime) void AEventSourceActor::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
float time = GetGameTimeSinceCreation();
if (time - timerLastTime > 15.0) {
timerLastTime = time;
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "seconds elapsed");
redis->Unsubscribe(TEXT("second"));
redis->Subscribe(TEXT("second"));
}
// NB: Handled by RedisObject internal delegate // NB: Handled by RedisObject internal delegate
//redis->Tick(DeltaTime); //redis->Tick(DeltaTime);
@@ -77,6 +77,9 @@ private:
UFUNCTION() UFUNCTION()
void InternalSubscribeCallback(FString Channel, FString Message); void InternalSubscribeCallback(FString Channel, FString Message);
// For a timer calculation.
float timerLastTime = 0.0f;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;