Ejemplo n.º 1
0
    public function showMain()
    {
        $this->flushConfigCache();
        $form = new Curry_Form(array('url' => url('', $_GET), 'method' => 'post', 'elements' => array('job_handler' => array('text', array('label' => 'Job handler', 'value' => Curry_Core::$config->modules->contrib->CurryGearman->jobHandler, 'placeholder' => 'Leave empty to use default')), 'token' => array('text', array('label' => 'Token', 'description' => 'To execute the listener from the browser, a hash is required.', 'value' => Curry_Core::$config->modules->contrib->CurryGearman->token, 'required' => true, 'placeholder' => 'Enter a random string')), 'save' => array('submit', array('label' => 'Save')))));
        if (isPost() && $form->isValid($_POST)) {
            $values = $form->getValues(true);
            $this->saveConfig($values);
            return;
        }
        $webWorkerUrl = url(Curry_Core::$config->curry->baseUrl . 'gearman_listener.php/', array('hash' => Common_Gearman_Listener::getHash()))->getAbsolute();
        $html = <<<HTML
{$form}
<p><a href="{$webWorkerUrl}" target="_blank">Click here to execute Gearman web worker.</a></p>
HTML;
        $this->addMainContent($html);
    }
Ejemplo n.º 2
0
<?php

/**
 * Job listener for the Gearman package.
 *
 * @author  Jose F. D'Silva
 * @package  Gearman
 */
use Monolog\Logger;
require_once 'init.php';
$listener = new Common_Gearman_Listener();
$logger = $listener->getLogger();
$listener->setJobHandler(function (GearmanJob $gearmanJob) use($logger) {
    $s = sprintf("Fetched job [handle: %s, uniqueId: %s]", $gearmanJob->handle(), $gearmanJob->unique());
    $logger->log(Logger::INFO, $s);
    $jobWrapper = new Common_Gearman_JobWrapper($gearmanJob, $logger);
    $task = $jobWrapper->getJob();
    if ($task) {
        $task->setLogger($logger);
        $task->setUniqueId($gearmanJob->unique());
        return $task->handle();
    }
    $s = sprintf("%s[uniqId: %s] is not a valid job instance. Job ignored.", $gearmanJob->handle(), $gearmanJob->unique());
    $logger->log(Logger::ERROR, $s);
})->listen();