summaryrefslogtreecommitdiff
path: root/utils/notify_short/listener.pl
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-09-10 04:05:56 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-09-10 04:05:56 +0000
commitb4f05e5e252de387c7863b0be77049541c2ce831 (patch)
tree929f8147786a06f276501f8611a34f6d2ca9ef52 /utils/notify_short/listener.pl
parent0f4c94aed0dcd612e1598a2d15bd97858fc6e563 (diff)
Added a script which will notify individuals of short parts via email in
nearly real time git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@56 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'utils/notify_short/listener.pl')
-rw-r--r--utils/notify_short/listener.pl46
1 files changed, 46 insertions, 0 deletions
diff --git a/utils/notify_short/listener.pl b/utils/notify_short/listener.pl
new file mode 100644
index 00000000..37f31d38
--- /dev/null
+++ b/utils/notify_short/listener.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+# This is the SL-Short listener. It listens for the "parts_short" signal and
+# when the signal comes in, prepares a list of short parts to be sent to
+# at least one person.
+#
+# By Chris Travers, Metatron Technology Consulting
+# chris@metatrontech.com
+#
+# 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 $sth;
+
+$dbh->do("LISTEN parts_short");
+while (1){ # loop infinitely
+ if ($dbh->func ('pg_notifies')){
+ &on_notify;
+ }
+ sleep $cycle_delay;
+}
+sub on_notify {
+ 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;
+}
+