本文整理汇总了PHP中Task::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Task::run方法的具体用法?PHP Task::run怎么用?PHP Task::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task::run方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTask
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());
}
示例2: testIsRunning
public function testIsRunning()
{
$task = new Task(['exec' => 'sleep 1']);
$this->assertFalse($task->isRunning());
$task->run();
$this->assertTrue($task->isRunning());
}
示例3: makeForks
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--;
}
}
}
示例4: fire
/**
* 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);
}
}
示例5: __construct
<?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";
}
}
示例6: task
/**
* 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;
}
示例7: header
<?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);
示例8: assert
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();
示例9: run
public function run()
{
parent::run();
}