コード例 #1
0
 protected function buildTubePattern($v)
 {
     $prefix = Job::config()->queuePrefix();
     return '#^' . preg_quote($prefix, '#') . '(' . str_replace('\\*', '([^\\n]+)?', preg_quote($v, '#')) . ')' . '_([\\d]{8})$#';
 }
コード例 #2
0
    print json_encode(array('127.0.0.1:11300'));
    exit;
}
if (!isset($_GET['signed'])) {
    die("\n<h1>ok</h1>\n");
}
use Gaia\Job;
$nonce = new Gaia\Nonce('test001');
$server = new Gaia\Container($_SERVER);
$hash = $server->HTTP_X_JOB_NONCE;
$id = $server->HTTP_X_JOB_ID;
$uri = $server->REQUEST_URI;
$valid = $nonce->check($hash, $uri);
$status = $valid ? 'complete' : 'failed';
if ($id) {
    header('X-JOB-ID: ' . $id);
}
if ($id && $valid) {
    Job::config()->addConnection(new Pheanstalk('127.0.0.1', '11300'));
    $job = Job::find($id);
    if (!$job->complete()) {
        $status = 'failed-to-mark-complete';
        $valid = FALSE;
    }
}
header('X-JOB-STATUS: ' . $status);
if (!$valid) {
    header($server->SERVER_PROTOCOL . ' 403 Forbidden');
}
echo "\n<h1>{$status}</h1>\n";
// EOF
コード例 #3
0
$start = microtime(TRUE);
$runner->watch($queue);
$runner->setTimelimit(20);
$runner->setMax(10);
$runner->attachDebugger($debugger = function ($v) {
    if ($v instanceof Exception) {
        $v = $v->__toString();
    }
    if (!is_scalar($v)) {
        strval($v);
    }
    $dt = "\n[" . date('H:i:s') . '] ';
    echo $dt . str_replace("\n", $dt, trim($v));
});
$debugger("kicking off job runner ...\n---------------------");
Job::config()->setHandler(function (Http\Request $request) use($debugger) {
    $out = "\nHTTP";
    if ($request->id) {
        $out .= " - " . $request->id;
    }
    $info = $request->response;
    if ($info->http_code != 200) {
        $out .= '-ERR';
    }
    $out .= ": " . $info->url;
    $post = substr(is_array($request->post) ? \Gaia\Http\Util::buildQuery($request->post) : $request->post, 0, 75);
    $out .= '  ' . $post;
    if (strlen($post) >= 75) {
        $out .= ' ...';
    }
    if (strlen($info->response_header) < 1) {
コード例 #4
0
    $job = new Job('http://127.0.0.1:11299/job.php?register=1');
    $job->ttr = 2;
    $job->task = 'register';
    $info = $runner->stats();
    $info['host'] = php_uname('n');
    if (function_exists('posix_getpid')) {
        $info['pid'] = posix_getpid();
    }
    $job->post = $info;
    return $job;
};
// run a check first to make sure which server to run.
$job = $register();
$job->run();
$runner->addTask($task = function () use($runner, $register) {
    $config = Job::config();
    if ($config->registering) {
        return;
    }
    $config->registering = TRUE;
    $runner->addJob($register(), array(CURLOPT_CONNECTTIMEOUT => 1, CURLOPT_HTTPHEADER => array('Connection: Keep-Alive', 'Keep-Alive: 300')));
});
$ct = $runner->flush($queue);
$debugger("JOBS flushed from the queue before starting: {$ct}");
$runner->addTask(function () use($debugger, $queue, $runner) {
    static $ct;
    if (!isset($ct)) {
        $ct = 0;
    }
    $stats = $runner->stats();
    $diff = $ct - $stats['processed'];