notifyexample.py
author Radek Brich <brich.radek@ifortuna.cz>
Tue, 06 May 2014 18:37:41 +0200
changeset 100 d6088dba8fea
parent 93 b72591087495
child 104 d8ff52a0390f
permissions -rwxr-xr-x
Add pgtool wrapper for all tools. Only this script will be installed into system bin.

#!/usr/bin/env python3
#
# Call "NOTIFY notifyexample" on target DB to wake up this program.
#

from pgtoolkit import toolbase, pgmanager


class NotifyExample(toolbase.SimpleTool):
    def __init__(self):
        toolbase.SimpleTool.__init__(self, name='notifyexample', desc='Sample program for listen/notify.')
        self.init()

    def main(self):
        # create another connection for notifies, copy parameters from connection 'target'
        self.pgm.create_conn_listen('target_listen', channel='notifyexample', copy_dsn='target')
        while True:
            ev = self.pgm.wait_for_notify('target_listen', timeout=None)
            if ev:
                print(ev)


tool = NotifyExample()
tool.main()