diff options
Diffstat (limited to 'utils/notify_short/listener.pl')
-rw-r--r-- | utils/notify_short/listener.pl | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/utils/notify_short/listener.pl b/utils/notify_short/listener.pl index dae23d0a..05b5afd0 100644 --- a/utils/notify_short/listener.pl +++ b/utils/notify_short/listener.pl @@ -7,40 +7,46 @@ # By Chris Travers, Metatron Technology Consulting # chris@metatrontech.com # -# Released under the GNU GPL v2.0 or later. See included GPL.txt for more +# Released under the GNU GPL v2.0 or later. See included GPL.txt for more # information. require "config.pl"; use DBI; my $dsn = "dbi:Pg:dbname=$database"; -my $dbh = DBI->connect($dsn, $db_user, $db_passwd, - { AutoCommit => 1, - PrintError => 0, - RaiseError => 1, } +my $dbh = DBI->connect( + $dsn, $db_user, + $db_passwd, + { + AutoCommit => 1, + PrintError => 0, + RaiseError => 1, + } ); my $sth; $dbh->do("LISTEN parts_short"); -while (1){ # loop infinitely - if ($dbh->func ('pg_notifies')){ - &on_notify; - } - sleep $cycle_delay; +while (1) { # loop infinitely + if ( $dbh->func('pg_notifies') ) { + &on_notify; + } + sleep $cycle_delay; } + sub on_notify { - open (MAIL, "|-", $sendmail); - $sth = $dbh->prepare(" + open( MAIL, "|-", $sendmail ); + $sth = $dbh->prepare( " SELECT partnumber, description, onhand, rop FROM parts WHERE onhand <= rop - "); - $sth->execute; - print MAIL $template_top; - while (($partnumber, $description, $avail, $rop) = $sth->fetchrow_array){ - write MAIL; - } - print MAIL $template_foot; - close MAIL; + " ); + $sth->execute; + print MAIL $template_top; + while ( ( $partnumber, $description, $avail, $rop ) = $sth->fetchrow_array ) + { + write MAIL; + } + print MAIL $template_foot; + close MAIL; } |