fix: [UI] Failed jobs are not considered as Queued

pull/7204/head
Jakub Onderka 2021-03-14 17:08:14 +01:00
parent d989759211
commit f518e720e1
4 changed files with 45 additions and 61 deletions

View File

@ -355,7 +355,7 @@ class ACLComponent extends Component
'jobs' => array(
'cache' => array('*'),
'getError' => array(),
'getGenerateCorrelationProgress' => array('*'),
'getGenerateCorrelationProgress' => array(),
'getProgress' => array('*'),
'index' => array(),
'clearJobs' => array()

View File

@ -1,23 +1,22 @@
<?php
App::uses('AppController', 'Controller');
/**
* @property Job $Job
*/
class JobsController extends AppController
{
public $components = array('Security' ,'RequestHandler', 'Session');
public $paginate = array(
'limit' => 20,
'order' => array(
'Job.id' => 'desc'
),
'limit' => 20,
'order' => array(
'Job.id' => 'desc'
),
);
public function index($queue = false)
{
if (!$this->_isSiteAdmin()) {
throw new MethodNotAllowedException();
}
if (!Configure::read('MISP.background_jobs')) {
throw new NotFoundException('Background jobs are not enabled on this instance.');
}
@ -26,21 +25,18 @@ class JobsController extends AppController
$workers = $this->Server->workerDiagnostics($issueCount);
$this->recursive = 0;
$queues = array('email', 'default', 'cache', 'prio', 'update');
if ($queue && in_array($queue, $queues)) {
if ($queue && in_array($queue, $queues, true)) {
$this->paginate['conditions'] = array('Job.worker' => $queue);
}
$jobs = $this->paginate();
foreach ($jobs as &$job) {
if ($job['Job']['process_id'] !== false) {
$job['Job']['job_status'] = $this->__jobStatusConverter(CakeResque::getJobStatus($job['Job']['process_id']));
$job['Job']['failed'] = false;
if ($job['Job']['status'] === 'Failed') {
$job['Job']['failed'] = true;
}
$job['Job']['failed'] = $job['Job']['job_status'] === 'Failed';
} else {
$job['Job']['status'] = 'Unknown';
$job['Job']['job_status'] = 'Unknown';
}
$job['Job']['worker_status'] = isset($workers[$job['Job']['worker']]) && $workers[$job['Job']['worker']]['ok'] ? true : false;
$job['Job']['worker_status'] = isset($workers[$job['Job']['worker']]) && $workers[$job['Job']['worker']]['ok'];
}
$this->set('list', $jobs);
$this->set('queue', $queue);
@ -63,34 +59,30 @@ class JobsController extends AppController
switch ($status) {
case 1:
return 'Waiting';
break;
case 2:
return 'Running';
break;
case 3:
return 'Failed';
break;
case 4:
return 'Completed';
break;
default:
return 'Unknown';
break;
}
}
public function getGenerateCorrelationProgress($id)
{
if (!self::_isSiteAdmin()) {
throw new NotFoundException();
}
$progress = $this->Job->findById($id);
$progress = $this->Job->find('first', [
'fields' => ['progress'],
'conditions' => ['id' => $id],
'recursive' => -1,
]);
if (!$progress) {
$progress = 0;
} else {
$progress = $progress['Job']['progress'];
$progress = (int)$progress['Job']['progress'];
}
return new CakeResponse(array('body' => json_encode($progress), 'type' => 'json'));
return $this->RestResponse->viewData($progress, 'json');
}
public function getProgress($type)

View File

@ -7,7 +7,7 @@
$stackTrace = "";
if (isset($response['backtrace']) && !empty($response['backtrace'])) {
foreach ($response['backtrace'] as $line) {
$stackTrace .= h($line) . '</br>';
$stackTrace .= h($line) . '<br>';
}
}
foreach ($fields as $name => $content):

View File

@ -28,7 +28,7 @@
</ul>
</div>
<script type="text/javascript">
var intervalArray = new Array();
var intervalArray = [];
function queueInterval(k, id) {
intervalArray[k] = setInterval(function() {
@ -82,28 +82,28 @@
)
);
?>
<div id="attributeList" class="attributeListContainer">
<div>
<?php echo $this->element('/genericElements/ListTopBar/scaffold', array('data' => $data)); ?>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('date_created', __('Date created'));?></th>
<th><?php echo $this->Paginator->sort('date_modified', __('Date modified'));?></th>
<th><?php echo $this->Paginator->sort('process_id', __('Process ID'));?></th>
<th><?php echo $this->Paginator->sort('worker', __('Worker'));?></th>
<th><?php echo $this->Paginator->sort('job_type', __('Job type'));?></th>
<th><?php echo $this->Paginator->sort('job_input', __('Input'));?></th>
<th><?php echo $this->Paginator->sort('message');?></th>
<th><?php echo $this->Paginator->sort('Org.name', __('Organisation name'));?></th>
<th><?php echo $this->Paginator->sort('status');?></th>
<th><?php echo $this->Paginator->sort('retries', __('Retries'));?></th>
<th><?php echo $this->Paginator->sort('progress');?></th>
<th><?php echo $this->Paginator->sort('id', __('ID'));?></th>
<th><?php echo $this->Paginator->sort('date_created', __('Date created'));?></th>
<th><?php echo $this->Paginator->sort('date_modified', __('Date modified'));?></th>
<th><?php echo $this->Paginator->sort('process_id', __('Process ID'));?></th>
<th><?php echo $this->Paginator->sort('worker', __('Worker'));?></th>
<th><?php echo $this->Paginator->sort('job_type', __('Job type'));?></th>
<th><?php echo $this->Paginator->sort('job_input', __('Input'));?></th>
<th><?php echo $this->Paginator->sort('message');?></th>
<th><?php echo $this->Paginator->sort('Org.name', __('Organisation name'));?></th>
<th><?php echo $this->Paginator->sort('status');?></th>
<th><?php echo $this->Paginator->sort('retries', __('Retries'));?></th>
<th><?php echo $this->Paginator->sort('progress');?></th>
</tr>
<?php
foreach ($list as $k => $item):
$progress = '100';
$startRefreshing = false;
if ($item['Job']['failed'] || $item['Job']['status'] == 3) {
if ($item['Job']['failed'] || $item['Job']['status'] == Job::STATUS_FAILED) {
$item['Job']['job_status'] = 'Failed';
$progress_message = __('Failed');
$progress_bar_type = 'progress progress-danger active';
@ -126,15 +126,15 @@
}
?>
<tr>
<td class="short"><?php echo h($item['Job']['id']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['id']); ?></td>
<td class="short"><?= $this->Time->time($item['Job']['date_created']) ?></td>
<td class="short"><?= $this->Time->time($item['Job']['date_modified']) ?></td>
<td class="short"><?php echo h($item['Job']['process_id']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['worker']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['job_type']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['job_input']); ?>&nbsp;</td>
<td><?php echo h($item['Job']['message']); ?>&nbsp;</td>
<td class="short"><?php echo isset($item['Org']['name']) ? h($item['Org']['name']) : 'SYSTEM'; ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['process_id']); ?></td>
<td class="short"><?php echo h($item['Job']['worker']); ?></td>
<td class="short"><?php echo h($item['Job']['job_type']); ?></td>
<td class="short"><?php echo h($item['Job']['job_input']); ?></td>
<td><?php echo h($item['Job']['message']); ?></td>
<td class="short"><?php echo isset($item['Org']['name']) ? h($item['Org']['name']) : 'SYSTEM'; ?></td>
<td class="short">
<?php
echo h($item['Job']['job_status']);
@ -145,13 +145,11 @@
endif;
?>
</td>
<td class="short"><?php echo h($item['Job']['retries']); ?>&nbsp;</td>
<td class="short"><?php echo h($item['Job']['retries']); ?></td>
<td style="width:200px;">
<div class="<?php echo $progress_bar_type; ?>" style="margin-bottom: 0px;">
<div id="bar<?php echo h($item['Job']['id']); ?>" class="bar" style="width: <?php echo $progress; ?>%;">
<?php
echo h($progress_message);
?>
<?= h($progress_message); ?>
</div>
</div>
<?php
@ -185,10 +183,4 @@
</ul>
</div>
</div>
<div class="actions <?php echo $debugMode;?>">
<ul class="nav nav-list">
</ul>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'admin', 'menuItem' => 'jobs'));
<?= $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'admin', 'menuItem' => 'jobs'));