New scheduler

This commit is contained in:
jygaulier
2012-03-07 11:08:54 +01:00
parent 72078aa836
commit 8c767d28c7
4 changed files with 22 additions and 35 deletions

View File

@@ -33,17 +33,14 @@ abstract class task_databoxAbstract extends task_abstract
protected function run2() protected function run2()
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
while($this->running) while($this->running)
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
try try
{ {
$conn = connection::getPDOConnection(); $conn = connection::getPDOConnection();
} }
catch(Exception $e) catch(Exception $e)
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->log($e->getMessage()); $this->log($e->getMessage());
$this->log(("Warning : abox connection lost, restarting in 10 min.")); $this->log(("Warning : abox connection lost, restarting in 10 min."));
@@ -53,12 +50,10 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
$this->running = false; $this->running = false;
$this->return_value = self::RETURNSTATUS_TORESTART; $this->return_value = self::RETURNSTATUS_TORESTART;
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
return; return;
} }
$this->set_last_exec_time(); $this->set_last_exec_time();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
try try
{ {
@@ -72,14 +67,12 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
} }
catch(Exception $e) catch(Exception $e)
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->task_status = self::STATUS_TOSTOP; $this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED; $this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array(); $rs = array();
} }
foreach($rs as $row) foreach($rs as $row)
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
if(!$this->running) if(!$this->running)
break; break;
@@ -96,7 +89,6 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
try try
{ {
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->load_settings(simplexml_load_string($row['settings'])); $this->load_settings(simplexml_load_string($row['settings']));
} }
catch(Exception $e) catch(Exception $e)
@@ -106,26 +98,18 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
} }
$this->current_state = self::STATE_OK; $this->current_state = self::STATE_OK;
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->process_sbas()->check_current_state(); $this->process_sbas()->check_current_state();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->process_sbas()->flush_records_sbas(); $this->process_sbas()->flush_records_sbas();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
} }
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->increment_loops(); $this->increment_loops();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->pause($duration); $this->pause($duration);
} }
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->process_sbas()->check_current_state(); $this->process_sbas()->check_current_state();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->process_sbas()->flush_records_sbas(); $this->process_sbas()->flush_records_sbas();
$this->set_status($this->return_value); $this->set_status($this->return_value);
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
return; return;
} }

View File

@@ -458,7 +458,8 @@ class task_period_cindexer extends task_abstract
{ {
socket_write($sock, 'Q', 1); socket_write($sock, 'Q', 1);
socket_write($sock, "\r\n", strlen("\r\n")); socket_write($sock, "\r\n", strlen("\r\n"));
sleep(5); for($i=0; $this->running && $i<5; $i++)
sleep(1);
$qsent = 'Q'; $qsent = 'Q';
$timetokill = time() + 10; $timetokill = time() + 10;
} }
@@ -502,7 +503,8 @@ class task_period_cindexer extends task_abstract
} }
} }
} }
sleep(5); for($i=0; $this->running && $i<5; $i++)
sleep(1);
} }
if($sock) if($sock)
@@ -559,11 +561,9 @@ class task_period_cindexer extends task_abstract
// is the cindexer alive ? // is the cindexer alive ?
if(!posix_kill($pid, 0)) if(!posix_kill($pid, 0))
{ {
printf("%d \n", __LINE__);
// dead... // dead...
if($sigsent === NULL) if($sigsent === NULL)
{ {
printf("%d \n", __LINE__);
// but it's not my fault // but it's not my fault
$this->log(_('task::cindexer:the cindexer crashed')); $this->log(_('task::cindexer:the cindexer crashed'));
$this->running = false; $this->running = false;
@@ -572,12 +572,10 @@ printf("%d \n", __LINE__);
} }
} }
printf("%d \n", __LINE__);
$this->check_task_status(); $this->check_task_status();
if($this->task_status == self::STATUS_TOSTOP) if($this->task_status == self::STATUS_TOSTOP)
{ {
printf("%d \n", __LINE__);
posix_kill($pid, ($sigsent=SIGINT)); posix_kill($pid, ($sigsent=SIGINT));
sleep(2); sleep(2);
} }
@@ -585,7 +583,6 @@ printf("%d \n", __LINE__);
$status = NULL; $status = NULL;
if(pcntl_wait($status, WNOHANG) == $pid) if(pcntl_wait($status, WNOHANG) == $pid)
{ {
printf("%d \n", __LINE__);
// child (indexer) has exited // child (indexer) has exited
if($sigsent == SIGINT) if($sigsent == SIGINT)
{ {
@@ -604,10 +601,8 @@ printf("%d \n", __LINE__);
} }
else else
{ {
printf("%d \n", __LINE__);
if($sigsent == SIGINT && time() > $timetokill) if($sigsent == SIGINT && time() > $timetokill)
{ {
printf("%d \n", __LINE__);
// must kill cindexer // must kill cindexer
$this->log(_('task::cindexer:killing the cindexer')); $this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K'; $qsent = 'K';

View File

@@ -256,25 +256,25 @@ switch ($parm['action'])
break; break;
*/ */
case 'PINGSCHEDULER_JS': case 'PINGSCHEDULER_JS':
$ret = array(); $ret = array('time'=> date("H:i:s") );
$ret['time'] = $dat = date("H:i:s");
$task_manager = new task_manager($appbox); $task_manager = new task_manager($appbox);
$ret['scheduler'] = $task_manager->get_scheduler_state2(); $ret['scheduler'] = $task_manager->get_scheduler_state2();
$ret['tasks'] = array(); $ret['tasks'] = array();
foreach ($task_manager->get_tasks(true) as $task) foreach ($task_manager->get_tasks(true) as $task)
{ {
$_t = array( $id = $task->get_task_id();
'id'=>$task->get_task_id() $ret['tasks'][$id] = array(
'id'=>$id
, 'pid' =>$task->get_pid() , 'pid' =>$task->get_pid()
, 'crashed'=>$task->get_crash_counter() , 'crashed'=>$task->get_crash_counter()
, 'completed'=>$task->get_completed_percentage() , 'completed'=>$task->get_completed_percentage()
, 'status'=>$task->get_status() , 'status'=>$task->get_status()
); );
$ret['tasks'][$_t['id']] = $_t;
} }
if(1) if(1)
{ {
$sql = 'SHOW PROCESSLIST'; $sql = 'SHOW PROCESSLIST';
@@ -290,7 +290,7 @@ switch ($parm['action'])
} }
} }
$output = json_encode($ret); $output = p4string::jsonencode($ret);
break; break;
case 'UNMOUNTBASE': case 'UNMOUNTBASE':
@@ -419,4 +419,6 @@ switch ($parm['action'])
$output = p4string::jsonencode($ret); $output = p4string::jsonencode($ret);
break; break;
} }
unset($appbox);
echo $output; echo $output;

View File

@@ -83,12 +83,12 @@ if($parm["act"] == "DELETETASK")
padding-left: 5px; padding-left: 5px;
padding-right: 5px; padding-right: 5px;
} }
#db_processlist table { table.db_processlist {
border: 1px solid #e0e0e0; border: 1px solid #e0e0e0;
border-collapse: collapse; border-collapse: collapse;
table-layout: fixed; table-layout: fixed;
} }
#db_processlist table th, table td { table.db_processlist th, table.db_processlist td {
height:auto; height:auto;
padding: 2px; padding: 2px;
margin: 0px; margin: 0px;
@@ -351,12 +351,16 @@ foreach($tasks as $t)
if(retPing.tasks[tid].pid) if(retPing.tasks[tid].pid)
{ {
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['edit']+')').addClass("context-menu-item-disabled");
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['stop']+')').removeClass("context-menu-item-disabled"); $(this.menu).find('.context-menu-item:eq('+this.optionsIdx['stop']+')').removeClass("context-menu-item-disabled");
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['start']+')').addClass("context-menu-item-disabled"); $(this.menu).find('.context-menu-item:eq('+this.optionsIdx['start']+')').addClass("context-menu-item-disabled");
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['delete']+')').addClass("context-menu-item-disabled");
} }
else else
{ {
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['edit']+')').removeClass("context-menu-item-disabled");
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['stop']+')').addClass("context-menu-item-disabled"); $(this.menu).find('.context-menu-item:eq('+this.optionsIdx['stop']+')').addClass("context-menu-item-disabled");
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['delete']+')').removeClass("context-menu-item-disabled");
if(retPing.scheduler && retPing.scheduler.pid) if(retPing.scheduler && retPing.scheduler.pid)
$(this.menu).find('.context-menu-item:eq('+this.optionsIdx['start']+')').removeClass("context-menu-item-disabled"); $(this.menu).find('.context-menu-item:eq('+this.optionsIdx['start']+')').removeClass("context-menu-item-disabled");
else else
@@ -667,7 +671,8 @@ foreach($tasks as $t)
success: function(ret) success: function(ret)
{ {
retPing = ret; // global retPing = ret; // global
$("#pingTime").empty().append(ret.time); if(ret.time)
$("#pingTime").empty().append(ret.time);
if(ret.scheduler) if(ret.scheduler)
{ {
if(ret.scheduler.status) if(ret.scheduler.status)
@@ -725,6 +730,7 @@ foreach($tasks as $t)
if(ret.db_processlist) if(ret.db_processlist)
{ {
var _table = document.createElement('table'); var _table = document.createElement('table');
_table.setAttribute('class', 'db_processlist');
for(p in ret.db_processlist) for(p in ret.db_processlist)
{ {
if(p==0) if(p==0)