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()
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
while($this->running)
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
try
{
$conn = connection::getPDOConnection();
}
catch(Exception $e)
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->log($e->getMessage());
$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->return_value = self::RETURNSTATUS_TORESTART;
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
return;
}
$this->set_last_exec_time();
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
try
{
@@ -72,14 +67,12 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
}
catch(Exception $e)
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array();
}
foreach($rs as $row)
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
if(!$this->running)
break;
@@ -96,7 +89,6 @@ $this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value))
try
{
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->load_settings(simplexml_load_string($row['settings']));
}
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->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$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->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->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$this->pause($duration);
}
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
$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->set_status($this->return_value);
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
return;
}

View File

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

View File

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

View File

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