예제 #1
0
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";
            }
        }
    }
}