Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Use limit and offset arguments in job and joblog context
Browse files Browse the repository at this point in the history
To avoid the retrieval of a too long json result message,
we now use the recently introduced limit and offset
arguments in the job and joblog context to retrieve the desired
result in chunks which are merged together.
  • Loading branch information
fbergkemper committed Aug 24, 2017
1 parent d2a69ec commit 2c3f39f
Showing 1 changed file with 72 additions and 51 deletions.
123 changes: 72 additions & 51 deletions module/Job/src/Job/Model/JobModel.php
Expand Up @@ -38,35 +38,39 @@ class JobModel
*/
public function getJobs(&$bsock=null, $jobname=null, $days=null)
{
if(isset($bsock)) {
if($days == "all") {
if($jobname == "all") {
if (isset($bsock)) {
if ($days == "all") {
if ($jobname == "all") {
$cmd = 'llist jobs';
}
else {
} else {
$cmd = 'llist jobs jobname="'.$jobname.'"';
}
}
else {
if($jobname == "all") {
} else {
if ($jobname == "all") {
$cmd = 'llist jobs days='.$days;
}
else {
} else {
$cmd = 'llist jobs jobname="'.$jobname.'" days='.$days;
}
}
$result = $bsock->send_command($cmd, 2, null);
if(preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) {
//return false;
$error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $error['result']['error'];
}
else {
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $jobs['result']['jobs'];
$limit = 1000;
$offset = 0;
$retval = array();
while (true) {
$result = $bsock->send_command($cmd . ' limit=' . $limit . ' offset=' . $offset, 2, null);
if (preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) {
$error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $error['result']['error'];
} else {
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if ( empty($jobs['result']['jobs']) || is_null($jobs['result']['jobs']) ) {
return $retval;
} else {
$retval = array_merge($retval, $jobs['result']['jobs']);
}
}
$offset = $offset + $limit;
}
}
else {
} else {
throw new \Exception('Missing argument.');
}
}
Expand All @@ -84,34 +88,44 @@ public function getJobs(&$bsock=null, $jobname=null, $days=null)
*/
public function getJobsByStatus(&$bsock=null, $jobname=null, $status=null, $days=null, $hours=null)
{
if(isset($bsock, $status)) {
if(isset($days)) {
if($days == "all") {
if (isset($bsock, $status)) {
if (isset($days)) {
if ($days == "all") {
$cmd = 'llist jobs jobstatus='.$status.'';
}
else {
} else {
$cmd = 'llist jobs jobstatus='.$status.' days='.$days.'';
}
}
elseif(isset($hours)) {
if($hours == "all") {
} elseif (isset($hours)) {
if ($hours == "all") {
$cmd = 'llist jobs jobstatus='.$status.'';
}
else {
} else {
$cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.'';
}
}
else {
} else {
$cmd = 'llist jobs jobstatus='.$status.'';
}
if($jobname != "all") {
if ($jobname != "all") {
$cmd .= ' jobname="'.$jobname.'"';
}
$result = $bsock->send_command($cmd, 2, null);
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return array_reverse($jobs['result']['jobs']);
}
else {
$limit = 1000;
$offset = 0;
$retval = array();
while (true) {
$result = $bsock->send_command($cmd . ' limit=' . $limit . ' offset=' . $offset, 2, null);
if (preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) {
$error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $error['result']['error'];
} else {
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if ( empty($jobs['result']['jobs']) || is_null($jobs['result']['jobs']) ) {
return array_reverse($retval);
} else {
$retval = array_merge($retval, $jobs['result']['jobs']);
}
}
$offset = $offset + $limit;
}
} else {
throw new \Exception('Missing argument.');
}
}
Expand Down Expand Up @@ -149,19 +163,26 @@ public function getJobLog(&$bsock=null, $id=null)
{
if(isset($bsock, $id)) {
$cmd = 'list joblog jobid='.$id.'';
$result = $bsock->send_command($cmd, 2, null);
if(preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) {
//return false;
$error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $error['result']['error'];
}
else {
$log = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $log['result']['joblog'];
$limit = 1000;
$offset = 0;
$retval = array();
while (true) {
$result = $bsock->send_command($cmd . ' limit=' . $limit . ' offset=' . $offset, 2, null);
if(preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) {
$error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $error['result']['error'];
}
else {
$log = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if ( empty($log['result']['joblog']) || is_null($log['result']['joblog']) ) {
return $retval;
} else {
$retval = array_merge($retval, $log['result']['joblog']);
}
}
$offset = $offset + $limit;
}

}
else {
} else {
throw new \Exception('Missing argument.');
}
}
Expand Down

0 comments on commit 2c3f39f

Please sign in to comment.