diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 23e435b97950021228cea9a74c28edc62aaf5816..fa18d790d1a2511807d02431142c7b10bc07a231 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:20.10.9 variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 2.5.4 + IMAGE_VER: 2.6.0 services: - docker:20.10.9-dind diff --git a/lib/CF/Controller/Websockets.pm b/lib/CF/Controller/Websockets.pm index 0c8c4697c69846cc7e1e060c5e98953dce34a889..7c821e8d0d8f2c961094976045480d733eef49bc 100644 --- a/lib/CF/Controller/Websockets.pm +++ b/lib/CF/Controller/Websockets.pm @@ -23,11 +23,20 @@ sub main { $c->res->headers->add('Sec-WebSocket-Extensions' => 'permessage-deflate'); } - $c->redis->pubsub->listen( - notify => sub($pubsub, $payload) { + my $pubsub; + + if ($c->cfg->{message_broker} eq 'redis') { + $pubsub = $c->redis->pubsub; + $pubsub->listen(notify => sub($pubsub, $payload) { $c->send(decode("UTF-8", $payload)); - } - ); + }); + } + else { + $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); + $pubsub->listen(notify => sub($pubsub, $payload) { + $c->send($payload); + }); + } $c->on(json => sub( $c, $message ) { if ( $message->{event} eq 'KEEPALIVE' ) { @@ -99,7 +108,7 @@ sub main { }); $c->on(finish => sub ($c, $code, $reason = undef) { - $c->redis->pubsub->unlisten('notify'); + $pubsub->unlisten('notify'); $c->app->log->debug("WebSocket closed with status $code"); }); } diff --git a/lib/CF/Helpers/Core.pm b/lib/CF/Helpers/Core.pm index 36cbc28e2a2ff7f7877bf3a82e72602d90a8cd00..a952083c3651c42507d27cd24db6670d93677b45 100644 --- a/lib/CF/Helpers/Core.pm +++ b/lib/CF/Helpers/Core.pm @@ -203,12 +203,19 @@ sub register ($class, $self, $conf) { $self->helper( notify => sub ( $c, $event, $payload ) { - my $content = encode_json ({ + my $content = { event => $event, payload => $payload, - }); + }; + + if ($self->cfg->{message_broker} eq 'redis' ) { + $self->redis->pubsub->notify( notify => encode_json($content) ); + } + else { + my $pubsub = Mojo::Pg::PubSub->new(pg => $self->pg); + $pubsub->json('notify')->notify( notify => $content ); + } - $self->redis->pubsub->notify( notify => $content ); }); }