mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 19:43:16 +00:00
Fix build
This commit is contained in:
@@ -25,6 +25,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;
|
||||||
|
|
||||||
@@ -37,30 +38,30 @@ class module_console_taskrun extends Command
|
|||||||
|
|
||||||
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
|
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
|
||||||
$this->addOption(
|
$this->addOption(
|
||||||
'runner'
|
'runner'
|
||||||
, 'r'
|
, 'r'
|
||||||
, InputOption::VALUE_REQUIRED
|
, InputOption::VALUE_REQUIRED
|
||||||
, 'The name of the runner (manual, scheduler...)'
|
, 'The name of the runner (manual, scheduler...)'
|
||||||
, task_abstract::RUNNER_MANUAL
|
, task_abstract::RUNNER_MANUAL
|
||||||
);
|
);
|
||||||
$this->addOption(
|
$this->addOption(
|
||||||
'nolog'
|
'nolog'
|
||||||
, NULL
|
, NULL
|
||||||
, 1 | InputOption::VALUE_NONE
|
, 1 | InputOption::VALUE_NONE
|
||||||
, 'do not log to logfile'
|
, 'do not log to logfile'
|
||||||
, NULL
|
, NULL
|
||||||
);
|
);
|
||||||
$this->setDescription('Run task');
|
$this->setDescription('Run task');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sig_handler($signo)
|
function sig_handler($signo)
|
||||||
{
|
{
|
||||||
if($this->task)
|
if ($this->task)
|
||||||
{
|
{
|
||||||
$this->task->log(sprintf("signal %s received", $signo));
|
$this->task->log(sprintf("signal %s received", $signo));
|
||||||
if($signo == SIGTERM)
|
if ($signo == SIGTERM)
|
||||||
$this->task->set_running(false);
|
$this->task->set_running(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,52 +79,56 @@ class module_console_taskrun extends Command
|
|||||||
|
|
||||||
$task_id = (int) $input->getArgument('task_id');
|
$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.');
|
throw new \RuntimeException('Argument must be an Id.');
|
||||||
|
|
||||||
$appbox = appbox::get_instance();
|
$appbox = appbox::get_instance();
|
||||||
$task_manager = new task_manager($appbox);
|
$task_manager = new task_manager($appbox);
|
||||||
$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)
|
||||||
{
|
{
|
||||||
$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();
|
$registry = $appbox->get_registry();
|
||||||
$schedFile = $registry->get('GV_RootPath') . 'tmp/locks/scheduler.lock';
|
$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)));
|
$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);
|
||||||
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
|
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()));
|
|
||||||
|
|
||||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
$this->task->run($runner, $input, $output);
|
||||||
{
|
|
||||||
$runner = task_abstract::RUNNER_MANUAL;
|
$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()
|
public function tick_handler()
|
||||||
{
|
{
|
||||||
static $start = FALSE;
|
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 ($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'))
|
||||||
$this->task->signal('SIGNAL_SCHEDULER_DIED');
|
$this->task->signal('SIGNAL_SCHEDULER_DIED');
|
||||||
else
|
else
|
||||||
$this->task->set_status(task_abstract::STATUS_TOSTOP);
|
$this->task->set_status(task_abstract::STATUS_TOSTOP);
|
||||||
@@ -133,6 +138,6 @@ $this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=
|
|||||||
$start = time();
|
$start = time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user