Skip to content
Snippets Groups Projects
Verified Commit b5204726 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Prepnuti na redis messaging

parent f3880091
No related branches found
No related tags found
No related merge requests found
......@@ -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 => '');
......
......@@ -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");
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment