Guest User

Untitled

a guest
Sep 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. var pg = require('pg'),
  2. gearmanode = require('gearmanode'),
  3. gearmanClient,
  4. conString = 'tcp://username:password@localhost:5432/gonzalo',
  5. pgClient;
  6.  
  7. gearmanode.Client.logger.transports.console.level = 'error';
  8.  
  9. gearmanClient = gearmanode.client();
  10.  
  11. console.log('LISTEN myEvent');
  12. pgClient = new pg.Client(conString);
  13. pgClient.connect();
  14. pgClient.query('LISTEN myEvent');
  15. pgClient.on('notification', function (data) {
  16. console.log("33[34m" + new Date + '-33[0m payload', data.payload);
  17. gearmanClient.submitJob('sms.sender.one', data.payload);
  18. });
  19.  
  20. $dbconn = pg_connect("host=".$DB_SERVER." port=".$DB_PORT." user=".$DB_USER." password=".$DB_PASSWORD." dbname=".$DB);
  21.  
  22. $dbconn->exec('LISTEN "myEvent"');
  23.  
  24. $inc=0;
  25.  
  26. while (1) {
  27. $result = "";
  28.  
  29. $result = pg_get_notify($dbconn);
  30.  
  31. if ($result) {
  32. // Here, instead of echoing out the result, I will be parsing it
  33. // and inserting values from the result into another table
  34. echo '33[34m' + date('DATE_RFC2822') + '-33[0m payload', $result)."nn";
  35. $inc++;
  36. }
  37. }
Add Comment
Please, Sign In to add comment