Fix build

This commit is contained in:
Romain Neutron
2012-03-20 13:40:00 +01:00
parent d4e6a716d9
commit 4c7f3897bf

View File

@@ -25,6 +25,7 @@ use Symfony\Component\Console\Command\Command;
class module_console_taskrun extends Command
{
private $task;
private $shedulerPID;
@@ -57,10 +58,10 @@ class module_console_taskrun extends Command
function sig_handler($signo)
{
if($this->task)
if ($this->task)
{
$this->task->log(sprintf("signal %s received", $signo));
if($signo == SIGTERM)
if ($signo == SIGTERM)
$this->task->set_running(false);
}
}
@@ -78,14 +79,14 @@ 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);
$this->task = $task_manager->get_task($task_id);
if($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
{
$runner = task_abstract::RUNNER_MANUAL;
}
@@ -94,36 +95,40 @@ class module_console_taskrun extends Command
$runner = task_abstract::RUNNER_SCHEDULER;
$registry = $appbox->get_registry();
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
if(file_exists($schedFile))
if (file_exists($schedFile))
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
}
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks=1);
declare(ticks = 1);
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
$this->task->run($runner, $input, $output);
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
{
$runner = task_abstract::RUNNER_MANUAL;
}
}
public function tick_handler()
{
static $start = FALSE;
if($start === FALSE)
$start = time();
if(time() - $start > 0)
if ($start === FALSE)
{
if($this->shedulerPID)
$start = time();
}
if (time() - $start > 0)
{
if(!posix_kill($this->shedulerPID, 0))
if ($this->shedulerPID)
{
if(method_exists($this->task, 'signal'))
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);