fixes for windows

This commit is contained in:
jygaulier
2012-04-25 14:50:19 +02:00
parent 2316a58422
commit 137903fb36

46
lib/classes/module/console/taskrun.class.php Normal file → Executable file
View File

@@ -26,6 +26,7 @@ use Symfony\Component\Console\Command\Command;
class module_console_taskrun extends Command class module_console_taskrun extends Command
{ {
private $task; private $task;
private $shedulerPID; private $shedulerPID;
public function __construct($name = null) public function __construct($name = null)
@@ -67,12 +68,19 @@ class module_console_taskrun extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! setup::is_installed()) { if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up'); if ($this->task) {
$this->task->log(sprintf("signal %s received", $signo));
return 1; if ($signo == SIGTERM)
$this->task->set_running(false);
}
}
// printf("%s (%d) execute\n", __FILE__, __LINE__);
} }
$task_id = (int) $input->getArgument('task_id'); public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! setup::is_installed()) {
$output->writeln('Phraseanet is not set up');
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.'); throw new \RuntimeException('Argument must be an Id.');
@@ -82,27 +90,38 @@ class module_console_taskrun extends Command
$this->task = $task_manager->get_task($task_id); $this->task = $task_manager->get_task($task_id);
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) { if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$schedStatus = $task_manager->get_scheduler_state();
// printf("%s (%d) schedStatus=%s \n", __FILE__, __LINE__, var_export($schedStatus, true));
if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid'])
$this->shedulerPID = $schedStatus['pid'];
$runner = task_abstract::RUNNER_MANUAL; $runner = task_abstract::RUNNER_MANUAL;
} else { }
else {
$runner = task_abstract::RUNNER_SCHEDULER; $runner = task_abstract::RUNNER_SCHEDULER;
$registry = $appbox->get_registry(); $schedStatus = $task_manager->get_scheduler_state();
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock'; if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid'])
if (file_exists($schedFile)) $this->shedulerPID = $schedStatus['pid'];
$this->shedulerPID = (int) (trim(file_get_contents($schedFile)));
} }
register_tick_function(array($this, 'tick_handler'), true); register_tick_function(array($this, 'tick_handler'), true);
declare(ticks = 1); declare(ticks = 1);
if (function_exists('pcntl_signal'))
pcntl_signal(SIGTERM, array($this, 'sig_handler')); pcntl_signal(SIGTERM, array($this, 'sig_handler'));
try {
$this->task->run($runner, $input, $output); $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())); } catch (Exception $e) {
$this->task->log(sprintf("taskrun : exception from 'run()', %s \n", $e->getMessage()));
return($e->getCode());
}
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) { if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$runner = task_abstract::RUNNER_MANUAL; $runner = task_abstract::RUNNER_MANUAL;
} }
} }
}
public function tick_handler() public function tick_handler()
{ {
@@ -113,6 +132,7 @@ class module_console_taskrun extends Command
} }
if (time() - $start > 0) { if (time() - $start > 0) {
// printf("%s (%d) : tick\n", __FILE__, __LINE__);
if ($this->shedulerPID) { if ($this->shedulerPID) {
if ( ! posix_kill($this->shedulerPID, 0)) { if ( ! posix_kill($this->shedulerPID, 0)) {
if (method_exists($this->task, 'signal')) if (method_exists($this->task, 'signal'))
@@ -120,10 +140,10 @@ class module_console_taskrun extends Command
else else
$this->task->set_status(task_abstract::STATUS_TOSTOP); $this->task->set_status(task_abstract::STATUS_TOSTOP);
} }
}
$start = time(); $start = time();
} }
} }
}
} }