Example #1
0
function thread_shutdown()
{
    $isError = false;
    if ($error = error_get_last()) {
        switch ($error['type']) {
            case E_ERROR:
            case E_CORE_ERROR:
            case E_COMPILE_ERROR:
            case E_USER_ERROR:
                $isError = true;
                break;
        }
    }
    if ($isError) {
        date_default_timezone_set('Europe/Ljubljana');
        if (defined("THREAD") && defined("THREAD_TYPE")) {
            print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Script execution halted ({$error['message']})\n";
        } else {
            print date("d.m.Y H:i:s") . " :: Script execution halted ({$error['message']})\n";
        }
        if (defined("THREAD") && defined("THREAD_TYPE")) {
            require_once dirname(__FILE__) . '/../common/lib/Net/Gearman/Client.php';
            print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Starting workers restart...\n";
            $set = new Net_Gearman_Set();
            $task = new Net_Gearman_Task("Worker_Restarter", 1);
            $task->type = Net_Gearman_Task::JOB_BACKGROUND;
            $set->addTask($task);
            $client = new Net_Gearman_Client(array('127.0.0.1:4730'));
            $client->runSet($set);
        }
    }
}
Example #2
0
 public function run()
 {
     $client = new Net_Gearman_Client(array('localhost:4730'));
     $this->JobSet->starttime = date('Y-m-d H:i:s');
     $this->JobSet->save();
     $client->runSet($this->taskList);
     if (!$this->background) {
         if ($this->taskList->finished()) {
             global $WorkerJobSetResults;
             $handles = $this->taskList->handles;
             $key_handles = array_keys($handles);
             for ($i = 0; $i < count($WorkerJobSetResults[$this->randomHash]); $i++) {
                 if (array_key_exists($key_handles[$i], $WorkerJobSetResults[$this->randomHash])) {
                     if ($WorkerJobSetResults[$this->randomHash][$key_handles[$i]]['done']) {
                         $job = Job::model()->find('id=:id', array(':id' => $WorkerJobSetResults[$this->randomHash][$key_handles[$i]]['job_id']));
                         if ($job != null) {
                             if ($job == null) {
                                 $job = new Job();
                             }
                             $this->results[] = unserialize(base64_decode($job->result));
                             // echo "Done";
                             $job->needed = 0;
                             $job->save();
                         } else {
                             die("Some results didn't come...\n");
                         }
                     }
                 } else {
                     die("Some results didn't come...\n");
                 }
             }
             $this->JobSet->finishtime = date('Y-m-d H:i:s');
             if ($this->auto_destroy_results) {
                 $this->JobSet->needed = 0;
                 $this->JobSet->delete();
                 $this->JobSet = null;
             } else {
                 $this->JobSet->save();
             }
             return $this->results;
         }
         echo "Task set could not be finished!<br />\n";
         return false;
     } else {
         // background work
         return true;
     }
 }
Example #3
0
 /**
  * shutdown handler
  * @return void
  *
  */
 public function onShutdownHandler()
 {
     if ($e = error_get_last()) {
         if (defined("THREAD") && defined("THREAD_TYPE")) {
             require_once dirname(__FILE__) . '/../../../common/lib/Net/Gearman/Client.php';
             print date("d.m.Y H:i:s") . " :: " . THREAD_TYPE . " Thread :: " . str_pad(THREAD, 3, "0", STR_PAD_LEFT) . " :: Starting workers restart...\n";
             $set = new Net_Gearman_Set();
             $task = new Net_Gearman_Task("Worker_Restarter", 1);
             $task->type = Net_Gearman_Task::JOB_BACKGROUND;
             $set->addTask($task);
             $client = new Net_Gearman_Client(array('127.0.0.1:4730'));
             $client->runSet($set);
         }
         $this->raiseEvent('onEndRequest', new CEvent($this));
     }
 }
Example #4
0
 function __construct()
 {
     $post_id = $_REQUEST['id'];
     $this->db = $db = get_db_connectiuon();
     list($sessionkey, $cookies) = get_login_cookie($db);
     $this->sessionkey = $sessionkey;
     $this->page = $page = getPage();
     $pid = getmypid();
     $this->postid = $postid = (int) $_REQUEST['postid'];
     if (preg_match('%^http://([a-z\\-_.]+\\.)+\\w{2,4}(/mobile)?/post/\\d+$%i', $link = (string) $_REQUEST['permalink'])) {
         $this->permalink = $link;
     } else {
         $link = '';
     }
     $uniqkey = "{$pid}-{$postid}-{$sessionkey}";
     $set = new Net_Gearman_Set();
     $task = new Net_Gearman_Task('reblog', array(cookies => $cookies, postid => $postid, sessionkey => $sessionkey, permalink => $this->permalink, token => $_REQUEST['token'], uniqkey => $uniqkey), $uniqkey, Net_Gearman_Task::JOB_BACKGROUND);
     //   $task->attachCallback('result');
     $set->addTask($task);
     $client = new Net_Gearman_Client(array('localhost:37003'));
     $client->runSet($set);
 }
Example #5
0
<?php

require_once 'Net/Gearman/Client.php';
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$postid = $_REQUEST['postid'];
if ($email == '' or $password == '' or $postid == '') {
    print 0;
    exit;
}
$pid = getmypid();
$set = new Net_Gearman_Set();
$task = new Net_Gearman_Task('reblog', array('email' => $email, 'password' => $password, 'postid' => $postid), "{$pid}-{$postid}-{$email}", Net_Gearman_Task::JOB_BACKGROUND);
#$task->attachCallback('result');
$set->addTask($task);
$client = new Net_Gearman_Client(array('localhost:37003'));
$client->runSet($set);
print 1;
Example #6
0
 /**
  * See that task has handle and server assigned.
  *
  * @return void
  */
 public function testTaskStatus()
 {
     $client = new Net_Gearman_Client();
     $task = new Net_Gearman_Task('Reverse', range(1, 5));
     $task->type = Net_Gearman_Task::JOB_BACKGROUND;
     $set = new Net_Gearman_Set();
     $set->addTask($task);
     $client->runSet($set);
     $this->assertNotEquals('', $task->handle);
     $this->assertNotEquals('', $task->server);
 }