This commit is contained in:
jygaulier
2012-01-19 21:01:03 +01:00
parent e5828f06bb
commit 5a5f86a97b
7 changed files with 1079 additions and 653 deletions

View File

@@ -25,11 +25,16 @@ use Symfony\Component\Console\Command\Command;
class module_console_taskrun extends Command
{
private $task;
private $shedulerPID;
public function __construct($name = null)
{
parent::__construct($name);
$this->task = NULL;
$this->shedulerPID = NULL;
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
$this->addOption(
'runner'
@@ -54,21 +59,56 @@ class module_console_taskrun extends Command
$task_id = (int) $input->getArgument('task_id');
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
if($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
throw new \RuntimeException('Argument must be an Id.');
$appbox = appbox::get_instance();
$task_manager = new task_manager($appbox);
$task = $task_manager->get_task($task_id);
$this->task = $task_manager->get_task($task_id);
$runner = task_abstract::RUNNER_SCHEDULER;
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
if($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
{
$runner = task_abstract::RUNNER_MANUAL;
}
else
{
$runner = task_abstract::RUNNER_SCHEDULER;
$registry = $appbox->get_registry();
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
if(file_exists($schedFile))
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
}
$task->run($runner);
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks=1);
$this->task->run($runner);
printf("TASK QUIT\n");
return $this;
}
public function tick_handler()
{
static $start = FALSE;
if($start === FALSE)
$start = time();
if(time() - $start > 0)
{
if($this->shedulerPID)
{
if(!posix_kill($this->shedulerPID, 0))
{
if(method_exists($this->task, 'signal'))
$this->task->signal('SIGNAL_SCHEDULER_DIED');
else
$this->task->set_status(task_abstract::STATUS_TOSTOP);
}
}
$start = time();
}
}
}