function parse_rule($rules, $rule, $data = false) { if ($rule->rule->type == "follow_links") { $url = $rule->rule->url; $pq = new tidyPQ($url); $links = pq($rule->rule->selector); $results = array(); foreach ($links as $link) { $results[] = stripslashes(pq($link)->attr("href")); print "parse rule "; if (!in_queue($rule->set, $rule->rule->next_rule, array(stripslashes(pq($link)->attr("href"))))) { enqueue($rule->set, $rule->rule->next_rule, array(stripslashes(pq($link)->attr("href")))); } } //parse_rule( $rules, $rules[ $rule->rule->next_rule ], $results ); } else { if ($rule->rule->type == "get_data" && $data) { foreach ($data as $url) { if (substr($url, 0, strlen($rule->rule->url)) == $rule->rule->url) { $pq = new tidyPQ($url); $results = array(); foreach ($rule->rule->selectors as $target => $selector) { $sel = substr($selector, 0, strpos($selector, "%")); $get = substr($selector, strpos($selector, "%") + 1); //$result = pq( $sel ); if ($get == "text") { $result = pq($sel)->text(); } elseif (substr($get, 0, 5) == "attr=") { $result = pq($sel)->attr(substr($get, 5)); } $results[$target] = $result; } store_result($rule->set, $rule->id, $results); } else { store_result($rule->set, $rule->id, $url); } } } } }
print "Timeout, requeueing job {$i}: {$job['cmd']}\n"; $queueing = true; } elseif (isTerminated($job)) { print "Job {$i} died, requeueing: {$job['cmd']}\n"; removeJobStatus($job); $queueing = true; } else { $queueing = false; } if ($queueing) { $wiki = $job['wiki']; if (!isset($initialisedWikis[$wiki])) { startWiki($wiki); $initialisedWikis[$wiki] = true; } enqueue($job); $queueTimes[$i] = time(); } } sleep(10); } //------------------------------------------------------------ function getQueueSize() { global $queueSock; if (fwrite($queueSock, "size\n") === false) { die("Unable to write to queue server\n"); } $response = fgets($queueSock); if ($response === false) { die("Unable to read from queue server\n");
} save_research_queue($uid, array_values($queue)); } switch ($act) { case "show": show(); status(); show_research(); break; case "start": start(); status(); show_research(); break; case "enqueue": enqueue(); status(); show_research(); break; case "qremove": qremove(); status(); show_research(); break; case "qmove": qmove(); status(); show_research(); break; default: status();
<?php require 'queue.php'; foreach (range(1, 5) as $number) { enqueue('T' . $number); } var_dump($queue); function makeACall($duration) { $telefonistka = dequeue(); echo $telefonistka, ' handled the call '; } makeACall(10); var_dump($queue);
function route_post_order_action($local_id) { global $MC_Text; if (!preg_match('/^\\d+$/', $local_id)) { status(HTTP_NOT_FOUND); exit; } $member = authOpenAPIMember(); if ($member === FALSE) { status(HTTP_FORBIDDEN); exit; } $uid = $member['id']; $order = get_order($local_id); if ($order === FALSE) { status(HTTP_NOT_FOUND); exit; } $response = array(); $act = $_POST['act']; switch ($act) { case 'cancel': if ($order['uid'] != $member['id']) { status(HTTP_FORBIDDEN); exit; } if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) { return json_error('ORDER_CANCELLED'); } if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) { return json_error('ORDER_COMMITTED'); } // Start and lock 'reverse-order' transaction $temp = start_order_transaction($uid, -$order['amount']); if ($temp === FALSE) { return json_error('START_TRANS'); } // Set order 'DELETED' flag $res = $MC_Text->increment("flags-1_{$local_id}", FLAG_DELETED); if ($res === FALSE) { // Cancel transaction delete_temp_transaction($temp); return json_error('CANCEL_ORDER'); } // Commit 'reverse-order' transaction commit_transaction($temp); $response['ok'] = TRUE; // Send to common queue enqueue(array('cancel' => $local_id), ''); // Refresh balance $response['balance'] = formatBalance('USR', $uid); $response['order_balance'] = formatBalance('ORD', $uid); // Send to user's queue enqueue(array('cancel' => $local_id, 'balance' => $response['balance']), $uid); break; case 'commit': # Prevent from committing own orders #if ($order['uid'] == $member['id']) { # status(HTTP_FORBIDDEN); # exit; #} if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) { return json_error('ORDER_CANCELLED'); } if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) { return json_error('ORDER_COMMITTED'); } // Start and lock 'commit-order' transaction $temp = start_commit_order_transaction($uid, $order['uid'], $order['amount']); if ($temp === FALSE) { return json_error('START_TRANS'); } // Set order 'COMMITTED' flag $resp = $MC_Text->increment("flags-1_{$local_id}", FLAG_REPLIED); if ($resp === FALSE) { // Cancel transaction delete_temp_transaction($temp); return json_error('COMMIT_ORDER'); } // Commit 'commit-order' transaction $resp = commit_transaction($temp); # TODO: Store transaction id in the order $response['ok'] = TRUE; // Refresh balance $response['balance'] = formatBalance('USR', $uid); $response['order_balance'] = formatBalance('ORD', $uid); $author = $order['uid']; // Send to user's queue if ($uid != $author) { enqueue(array('commit' => $local_id, 'balance' => $response['balance']), $uid); } // Send to common queue enqueue(array('commit' => $local_id), ''); // Render author's html global $i; global $page; $i = get_order($local_id); $page = array('member' => array('id' => $author)); ob_start(); include 'templates/_order.php'; $html = ob_get_clean(); // Send to author's queue $data = array('commit' => $local_id, 'order' => $i, 'html' => $html); if ($author == $uid) { $data['balance'] = $response['balance']; } enqueue($data, $author); break; default: status(HTTP_BAD_REQUEST); exit; } send_header('Content-Type: application/json; charset=utf-8'); echo json_encode($response); }