Skip to content

Commit

Permalink
Show duration of jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 17, 2019
1 parent 67efae2 commit 05cc5b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions htdocs/core/lib/date.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
* @param string $format Output format ('all': total delay days hour:min like "2 days 12:30",
* - 'allwithouthour': total delay days without hour part like "2 days",
* - 'allhourmin': total delay with format hours:min like "60:30",
* - 'allhourminsec': total delay with format hours:min:sec like "60:30:10",
* - 'allhour': total delay hours without min/sec like "60:30",
* - 'fullhour': total delay hour decimal like "60.5" for 60:30,
* - 'hour': only hours part "12",
Expand All @@ -185,7 +186,7 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt
if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours
if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days

if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin')
if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin' || $format == 'allhourminsec')
{
if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US

Expand Down Expand Up @@ -232,11 +233,15 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt
$sTime.= dol_print_date($iSecond,'hourduration',true);
}
}
if ($format == 'allhourmin')
elseif ($format == 'allhourminsec')
{
return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))).':'.sprintf("%02d",((int) ($iSecond % 60)));
}
elseif ($format == 'allhourmin')
{
return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60)));
}
if ($format == 'allhour')
elseif ($format == 'allhour')
{
return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600)));
}
Expand Down
14 changes: 10 additions & 4 deletions htdocs/cron/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
print_liste_field_titre("CronMaxRun",$_SERVER["PHP_SELF"],"t.maxrun","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("CronNbRun",$_SERVER["PHP_SELF"],"t.nbrun","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre("CronDtLastLaunch",$_SERVER["PHP_SELF"],"t.datelastrun","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("CronDtLastResult",$_SERVER["PHP_SELF"],"t.datelastresult","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("Duration",$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("CronLastResult",$_SERVER["PHP_SELF"],"t.lastresult","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("CronLastOutput",$_SERVER["PHP_SELF"],"t.lastoutput","",$param,'',$sortfield,$sortorder);
print_liste_field_titre("CronDtNextLaunch",$_SERVER["PHP_SELF"],"t.datenextrun","",$param,'align="center"',$sortfield,$sortorder);
Expand Down Expand Up @@ -438,6 +438,9 @@
$object->priority = $obj->priority;
$object->processing = $obj->processing;

$datelastrun = $db->jdate($obj->datelastrun);
$datelastresult = $db->jdate($obj->datelastresult);

print '<tr class="oddeven">';

// Ref
Expand Down Expand Up @@ -510,12 +513,15 @@

// Date start last run
print '<td class="center">';
if (!empty($obj->datelastrun)) {print dol_print_date($db->jdate($obj->datelastrun),'dayhoursec');}
if (!empty($datelastrun)) {print dol_print_date($datelastrun,'dayhoursec');}
print '</td>';

// Date end last run
// Duration
print '<td class="center">';
if (!empty($obj->datelastresult)) {print dol_print_date($db->jdate($obj->datelastresult),'dayhoursec');}
if (!empty($datelastresult) && ($datelastresult >= $datelastrun)) {
print convertSecondToTime(max($datelastresult - $datelastrun, 1), 'allhourminsec');
//print '<br>'.($datelastresult - $datelastrun).' '.$langs->trans("seconds");
}
print '</td>';

// Return code of last run
Expand Down

0 comments on commit 05cc5b6

Please sign in to comment.