Ejemplo n.º 1
0
 public function testTask()
 {
     $mock = $this->getMock('stdClass', ['callback']);
     $mock->expects($this->exactly(1))->method('callback');
     $task = new Task('task_name', function () use($mock) {
         $mock->callback();
     });
     $context = $this->getMockBuilder('Deployer\\Task\\Context')->disableOriginalConstructor()->getMock();
     $task->run($context);
     $this->assertEquals('task_name', $task->getName());
     $task->desc('Task description.');
     $this->assertEquals('Task description.', $task->getDescription());
     $task->once();
     $this->assertTrue($task->isOnce());
     $task->onlyOn(['server']);
     $this->assertEquals(['server' => 0], $task->getOnlyOn());
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn([]);
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn('server');
     $this->assertEquals(['server' => 0], $task->getOnlyOn());
     $this->assertTrue($task->runOnServer('server'));
     $task->onlyOn();
     $this->assertTrue($task->runOnServer('server'));
     $task->setPrivate();
     $this->assertTrue($task->isPrivate());
 }
Ejemplo n.º 2
0
 public function testIsRunning()
 {
     $task = new Task(['exec' => 'sleep 1']);
     $this->assertFalse($task->isRunning());
     $task->run();
     $this->assertTrue($task->isRunning());
 }
Ejemplo n.º 3
0
 protected function makeForks()
 {
     $left = $this->processNum - count($this->children);
     while ($left > 0) {
         if (0 === ($pid = \pcntl_fork())) {
             $this->debug && fputs(STDERR, sprintf('Process #%d is started' . PHP_EOL, \getmypid()));
             $status = $this->task->run();
             exit($status);
         } else {
             $this->children[] = $pid;
             $left--;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //启动之前先检查进程是否还活着,如果还活着咱就退 windows 下 tasklist  /fi "PID eq xxxx"
     if (file_exists($this->filelock) && function_exists('posix_kill') && posix_kill(intval(file_get_contents($this->filelock)), 0)) {
         die("pid exists,exit");
     }
     file_put_contents($this->filelock, getmypid());
     Tasks::where("status", "execute")->update(array("status" => "created"));
     while (true) {
         //获取任务,执行任务
         $tasks = Tasks::where('status', 'created')->lists('id');
         foreach ($tasks as $_id) {
             //TaskHelper
             Task::run($_id);
         }
         sleep(1);
     }
 }
Ejemplo n.º 5
0
<?php

/**
 * 本脚本作用,检测采购商社区的表和discuzx3的表的差异性
 */
$task = new Task();
$task->run();
class Task
{
    public function __construct()
    {
        $this->discuzx3 = new Db("discuzx3");
        $this->buyer = new Db("buyer");
    }
    public function run()
    {
        //$this->checkTables();
        $this->checkColumns();
    }
    /**
     * 检测表差异
     */
    public function checkTables()
    {
        $tablesDz = $this->discuzx3->getTables();
        $tableHome = $this->buyer->getTables();
        foreach ($tablesDz as $value) {
            if (!in_array($value, $tableHome)) {
                echo "表 " . $value . " 不存在,需要处理\n";
            }
        }
Ejemplo n.º 6
0
Archivo: pantr.php Proyecto: pago/pantr
 /**
  * Register a new task and return it for further specification.
  *
  * This is the main entrance point for pantrfiles.
  * <code>pantr::task('foo', 'some description')
  * ->run(function() { pantr::writeln('Hello World!'); });
  *
  * This method is heavily overloaded. You can invoke it in any of the following ways:
  * - task(string $name): This will create a new task or return an existing one
  * - task(string $name, string $desc): This will create a new task with the specified
  * 				name and description or set the description of an existing task
  * - task(string $name, callable $fn): Creates a new task or updates the tasks execution code
  * - task(string $name, string $desc, callable $fn): Create or redefine an existing task
  *
  * @return Task A new or existing task with the specified $name.
  */
 public static function task($name, $fnOrDesc = null, $fn = null)
 {
     if (isset(self::$taskRepository[$name])) {
         $task = self::$taskRepository[$name];
         if (!is_null($fnOrDesc)) {
             if (is_callable($fnOrDesc)) {
                 $task->run($fnOrDesc);
             } else {
                 if (is_string($fnOrDesc)) {
                     $task->setDescription($fnOrDesc);
                 } else {
                     throw new \InvalidArgumentException('Second parameter must be either string or callable');
                 }
             }
         }
         if (!is_null($fn)) {
             if (is_callable($fn)) {
                 $task->run($fn);
             } else {
                 throw new \InvalidArgumentException('Third parameter must be callable!');
             }
         }
     } else {
         $task = new Task($name);
         if (is_null($fnOrDesc) && is_null($fn)) {
             $task->setDescription('n/a');
         }
         if (is_null($fn) && is_callable($fnOrDesc)) {
             $task->run($fnOrDesc);
         } else {
             if (is_string($fnOrDesc)) {
                 $task->setDescription($fnOrDesc);
             }
         }
         if (!is_null($fn) && is_callable($fn)) {
             $task->run($fn);
         }
         self::$taskRepository->registerTask($task);
     }
     return $task;
 }
Ejemplo n.º 7
0
<?php

header("Content-Type: text/plain");
define("BASE_DIR", dirname(__FILE__));
require_once BASE_DIR . "/include/constants.inc";
require_once BASE_DIR . "/include/globals.inc";
require_once BASE_DIR . "/include/misc.inc";
require_once BASE_DIR . "/include/dd.inc";
require_once BASE_DIR . "/include/mail.inc";
// execute some task if any.
Task::run(TASK_RUNNING_DURATION);
$type = "task";
$classname = Record::get_classname($type);
eval('$remaining_tasks = ' . $classname . '::get_progression($type, $_POST["event_id"]);');
echo join(",", $remaining_tasks);
Ejemplo n.º 8
0
        assert($request == 'start');
        $test1_id = $this->api->send_async($this->api->prefix() . 'f1', '0');
        list(, $test1_check, $test1_id_check) = $this->api->recv_async(null, $test1_id);
        assert($test1_id_check == $test1_id);
        assert($test1_check == 'done');
        list(, $test2_check, $test2_id_check) = $this->api->send_sync($this->api->prefix() . 'g1', 'prefix_');
        assert($test2_check == 'prefix_suffix');
        echo "messaging sequence3 end php\n";
        $this->api->send_async($this->api->prefix() . 'sequence1', 'start');
        $this->api->return_($command, $name, $pattern, '', 'end', $timeout, $trans_id, $pid);
    }
}
$thread_count = \CloudI\API::thread_count();
assert($thread_count == 1);
$main_thread = new Task(new \CloudI\API(0));
$main_thread->run();
/*
// commented out due to PHP threads not having
// readily available installation packages
$thread_count = \CloudI\API::thread_count();
assert($thread_count >= 1);
    
$threads = array();
for ($i = 0; $i < $thread_count; $i++)
{
    $threads[] = new Task(new \CloudI\API($i));
}
foreach ($threads as $t)
    $t->start();
foreach ($threads as $t)
    $t->join();
Ejemplo n.º 9
0
 public function run()
 {
     parent::run();
 }