function sendQueuedRequests() { // TODO: execute this method! ;) $qb = org_maemo_userdata_webhooks_queue::new_query_builder(); $qb->add_order('id'); $queued = $qb->execute(); $stuck_urls = array(); foreach ($queued as $item) { if (!in_array($item->url, $stuck_urls)) { echo "sending item #" . $item->id . ' to "' . $item->url . '"' . "\n"; try { $res = _sendHttpRequest($item->url, $item->payload); if (false === $res) { throw new Exception(); } else { $item->delete(); echo "-> ok\n"; } } catch (Exception $e) { // error. will retry later. blocking this webhook for now $stuck_urls[] = $item->url; echo "-> url didn't answer in a meaningful way. skipping it for now\n"; } } } }
private static function broadcastTransaction(org_maemo_userdata_transaction $trx) { $cfg = midgardmvc_core::get_instance()->configuration; $user = self::userByUuid($trx->useruuid); $data = json_encode(array('uuid' => $trx->apiuuid, 'action' => $trx->action, 'timestamp' => $trx->metadata->created->format(DATE_W3C), 'data' => self::personToArray($user))); foreach ($cfg->webhooks as $webhook) { $que = new org_maemo_userdata_webhooks_queue(); $que->url = $webhook['url']; $que->payload = $data; $que->create(); } }