r59044 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59043‎ | r59044 | r59045 >
Date:00:17, 14 November 2009
Author:straussd
Status:ok
Tags:
Comment:
Add more logging. Add fallback currency conversion. Add timeout for when no items are waiting in the queue.
Modified paths:
  • /civicrm/trunk/sites/all/modules/queue2civicrm/Stomp.php (modified) (history)
  • /civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm.module
@@ -27,6 +27,12 @@
2828 'type' => MENU_LOCAL_TASK,
2929 );
3030
 31+ $items['queue2civicrm'] = array(
 32+ 'access callback' => TRUE,
 33+ 'type' => MENU_CALLBACK,
 34+ 'page callback' => 'queue2civicrm_batch_process',
 35+ );
 36+
3137 return $items;
3238 }
3339
@@ -98,6 +104,12 @@
99105 * Implementation of hook_cron().
100106 */
101107 function queue2civicrm_cron() {
 108+ queue2civicrm_batch_process();
 109+}
 110+
 111+function queue2civicrm_batch_process() {
 112+ set_time_limit(10);
 113+
102114 $processed = 0;
103115
104116 watchdog('queue2civicrm', 'Attempting to process up to ' . variable_get('queue2civicrm_batch', 0) . ' contribution(s).');
@@ -157,12 +169,15 @@
158170 function queue2civicrm_dequeue() {
159171 $con = _queue2civicrm_stomp_connection();
160172
161 - if ($con) {
 173+ if ($con) {
162174 $con->subscribe(variable_get('queue2civicrm_subscription', '/queue/test'));
 175+
163176 $msg = $con->readFrame();
164177
165178 // Skip processing if no message to process.
166179 if ($msg !== FALSE) {
 180+ watchdog('queue2civicrm', 'Read frame:<pre>' . check_plain(print_r($msg, TRUE)) . '</pre>');
 181+ set_time_limit(60);
167182 try {
168183 queue2civicrm_import($msg);
169184 // Confirm successful processing of message.
@@ -173,6 +188,9 @@
174189 watchdog('queue2civicrm', 'Could not process frame from queue.', array(), WATCHDOG_ERROR);
175190 }
176191 }
 192+ else {
 193+ watchdog('queue2civicrm', 'Nothing to process.');
 194+ }
177195 }
178196
179197 return FALSE;
@@ -189,9 +207,18 @@
190208 if (!is_integer($contribution['date'])) {
191209 $contribution['date'] = strtotime($contribution['date']);
192210 }
 211+
 212+ watchdog('queue2civicrm', 'Contribution (pre-conversion):<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>');
193213
194 - dsm($contribution);
195 -
 214+ $contribution['fee'] = exchange_rate_convert($contribution['currency'], $contribution['fee'], $contribution['date']);
 215+ $contribution['gross'] = exchange_rate_convert($contribution['currency'], $contribution['gross'], $contribution['date']);
 216+ $contribution['net'] = exchange_rate_convert($contribution['currency'], $contribution['net'], $contribution['date']);
 217+
 218+ $contribution['gateway_txn_id'] .= ' ' . time();
 219+
 220+ //dsm($contribution);
 221+ watchdog('queue2civicrm', 'Contribution:<pre>' . check_plain(print_r($contribution, TRUE)) . '</pre>');
 222+
196223 // Save the contribution.
197224 fundcore_civicrm_contribution_insert($contribution);
198225 }
Index: civicrm/trunk/sites/all/modules/queue2civicrm/Stomp.php
@@ -515,17 +515,22 @@
516516 return false;
517517 }
518518
 519+ stream_set_timeout($this->_socket, 5);
519520 $rb = 1024;
520521 $data = '';
521522 do {
522523 $read = fgets($this->_socket, $rb);
523 - if ($read === false) {
524 - $this->_reconnect();
525 - return $this->readFrame();
 524+ $info = stream_get_meta_data($this->_socket);
 525+ if ($info['timed_out']) {
 526+ return FALSE;
526527 }
 528+ //if ($read === false) {
 529+ // $this->_reconnect();
 530+ // return $this->readFrame();
 531+ //}
527532 $data .= $read;
528533 $len = strlen($data);
529 - } while (($len < 2 || ! ($data[$len - 2] == "\x00" && $data[$len - 1] == "\n")));
 534+ } while ($read && ($len < 2 || ! ($data[$len - 2] == "\x00" && $data[$len - 1] == "\n")));
530535
531536 list ($header, $body) = explode("\n\n", $data, 2);
532537 $header = explode("\n", $header);

Status & tagging log