From b520472655d428939da24f8f26037e47181c5680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Mon, 29 Nov 2021 22:28:51 +0100 Subject: [PATCH] Prepnuti na redis messaging --- lib/CF/Controller/Program.pm | 14 ++++++++++++-- lib/CF/Controller/Websockets.pm | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/CF/Controller/Program.pm b/lib/CF/Controller/Program.pm index a526154..311ad34 100644 --- a/lib/CF/Controller/Program.pm +++ b/lib/CF/Controller/Program.pm @@ -34,7 +34,8 @@ sub update ($c) { return $c->error(404, 'Program entry not found') if ! $entry; my $update = $c->prepare_update_data( $entry, $c->req->json ); - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); +# PG_PUBSUB +# my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $guard = $c->schema->txn_scope_guard; # muze byt jen jeden aktualni bod programu @@ -46,7 +47,7 @@ sub update ($c) { $entry->update( $update ); - $pubsub->json('notify')->notify( notify => { + $c->redis->pubsub->json('notify')->notify( notify => { event => 'program_entry_changed', payload => { id => $entry->id, @@ -54,6 +55,15 @@ sub update ($c) { } }); +# PG_PUBSUB +# $pubsub->json('notify')->notify( notify => { +# event => 'program_entry_changed', +# payload => { +# id => $entry->id, +# %{ $update }, +# } +# }); + $guard->commit; $c->render(status => 204, text => ''); diff --git a/lib/CF/Controller/Websockets.pm b/lib/CF/Controller/Websockets.pm index 9600e85..41746d2 100644 --- a/lib/CF/Controller/Websockets.pm +++ b/lib/CF/Controller/Websockets.pm @@ -22,11 +22,16 @@ sub main { $c->res->headers->add('Sec-WebSocket-Extensions' => 'permessage-deflate'); } - my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); - - $pubsub->listen(notify => sub($pubsub, $payload) { - $c->send($payload); - }); + $c->redis->pubsub->json('notify')->listen( + notify => sub($pubsub, $payload) { + $c->send($payload); + } + ); +# PG_PUBSUB +# my $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' ) { @@ -98,7 +103,9 @@ sub main { }); $c->on(finish => sub ($c, $code, $reason = undef) { - $pubsub->unlisten('notify'); +# PG_PUBSUB +# $pubsub->unlisten('notify'); + $c->redis->pubsub->unlisten('notify'); $c->app->log->debug("WebSocket closed with status $code"); }); } -- GitLab