name my test sensors dobrica_
[zc] / pg-listen-zc.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5
6 use DBI;
7 use IO::Select;
8 use Data::Dump qw(dump);
9
10 my $dbh = DBI->connect("dbi:Pg:dbname=zc","dpavlin","", { RaiseError => 1, AutoCommit => 1 });
11
12 $dbh->do("LISTEN zc");
13
14 my $fd = $dbh->func("getfd");
15 my $sel = IO::Select->new($fd);
16
17
18 while (1) {
19         print "waiting...\n";
20         $sel->can_read;
21         my $notify = $dbh->func("pg_notifies");
22         if ($notify) {
23                 warn "# notify = ",dump($notify);
24                 my ($relname, $pid, $payload) = @$notify;
25                 print "$relname from PID $pid\n";
26         }
27 }
28