#1383 display task durations in webui
Merged 3 years ago by mikem. Opened 3 years ago by tkopecek.
tkopecek/koji issue1382  into  master

file modified
+40 -23
@@ -2,15 +2,16 @@ 

  #from kojiweb import util

  #from six.moves.urllib.parse import quote

  #import cgi

+ #import time

  

  #def printValue($key, $value, $sep=', ')

    #if $key in ('brootid', 'buildroot_id')

  <a href="buildrootinfo?buildrootID=$value">$value</a>

-   #elif $isinstance($value, list) 

- $sep.join([$str($val) for $val in $value]) 

+   #elif $isinstance($value, list)

+ $sep.join([$str($val) for $val in $value])

    #elif $isinstance($value, dict)

  $sep.join(['%s=%s' % (($n == '' and "''" or $n), $v) for $n, $v in $value.items()])

-   #else 

+   #else

  $value

    #end if

  #end def
@@ -26,7 +27,7 @@ 

    #elif $key != '__starstar'

    $prefix$key&nbsp;=&nbsp;$printValue($key, $value)<br/>

    #end if

-   #end for  

+   #end for

  #end def

  

  #def printOpts($opts)
@@ -130,26 +131,26 @@ 

          <strong>SCM URL:</strong> $params[0]<br/>

          <strong>Build Target:</strong> <a href="buildtargetinfo?name=$params[1]">$params[1]</a><br/>

          $printOpts($params[2])

- 	#elif $task.method == 'buildMaven'

- 	<strong>SCM URL:</strong> $params[0]<br/>

- 	<strong>Build Tag:</strong> <a href="taginfo?tagID=$buildTag.id">$buildTag.name</a><br/>

- 	#if $len($params) > 2

+         #elif $task.method == 'buildMaven'

+         <strong>SCM URL:</strong> $params[0]<br/>

+         <strong>Build Tag:</strong> <a href="taginfo?tagID=$buildTag.id">$buildTag.name</a><br/>

+         #if $len($params) > 2

          $printOpts($params[2])

          #end if

- 	#elif $task.method == 'wrapperRPM'

- 	<strong>Spec File URL:</strong> $params[0]<br/>

- 	#if 'locked' in $buildTarget

- 	#set $buildTag = $buildTarget

- 	<strong>Build Tag:</strong> <a href="taginfo?tagID=$buildTag.id">$buildTag.name</a><br/>

- 	#else

- 	<strong>Build Target:</strong> <a href="buildtargetinfo?targetID=$buildTarget.id">$buildTarget.name</a><br/>

- 	#end if

- 	#if $params[2]

- 	<strong>Build:</strong> <a href="buildinfo?buildID=$params[2].id">$koji.buildLabel($params[2])</a><br/>

- 	#end if

- 	#if $params[3]

- 	<strong>Task:</strong> <a href="taskinfo?taskID=$wrapTask.id">$koji.taskLabel($wrapTask)</a><br/>

- 	#end if

+         #elif $task.method == 'wrapperRPM'

+         <strong>Spec File URL:</strong> $params[0]<br/>

+         #if 'locked' in $buildTarget

+         #set $buildTag = $buildTarget

+         <strong>Build Tag:</strong> <a href="taginfo?tagID=$buildTag.id">$buildTag.name</a><br/>

+         #else

+         <strong>Build Target:</strong> <a href="buildtargetinfo?targetID=$buildTarget.id">$buildTarget.name</a><br/>

+         #end if

+         #if $params[2]

+         <strong>Build:</strong> <a href="buildinfo?buildID=$params[2].id">$koji.buildLabel($params[2])</a><br/>

+         #end if

+         #if $params[3]

+         <strong>Task:</strong> <a href="taskinfo?taskID=$wrapTask.id">$koji.taskLabel($wrapTask)</a><br/>

+         #end if

          #if $len($params) > 4

          $printOpts($params[4])

          #end if
@@ -320,16 +321,32 @@ 

      <tr>

        <th>Started</th><td>$util.formatTimeLong($task.start_time)</td>

      #end if

+     #set $end_ts = None

      #if $task.state == $koji.TASK_STATES.OPEN

      #if $estCompletion

      <tr>

-       <th>Est. Completion</th><td>$util.formatTimeLong($estCompletion)</td>

+       <th title="Estimation based on previous builds of same package">Est. Completion</th>

+       <td>$util.formatTimeLong($estCompletion)</td>

      </tr>

      #end if

      #elif $task.completion_time

      <tr>

        <th>Completed</th><td>$util.formatTimeLong($task.completion_time)</td>

      </tr>

+     #set $end_ts = $task.completion_ts

+     #end if

+     #if not $end_ts

+     #set $end_ts = time.time()

+     #end if

+     <tr>

+       <th title="From task's creation">Total time</th>

+       <td>$util.formatTimestampDifference($task.create_ts, $end_ts)</td>

+     </tr>

+     #if $task.start_time

+     <tr>

+       <th title="From task's start">Task time</th>

+       <td>$util.formatTimestampDifference($task.start_ts, $end_ts)</td>

+     </tr>

      #end if

      <tr>

        <th>Owner</th>

file modified
+10
@@ -30,6 +30,7 @@ 

  import six

  import ssl

  import stat

+ import time

  

  from six.moves import range

  #a bunch of exception classes that explainError needs
@@ -415,6 +416,15 @@ 

  formatTimeRSS = koji.formatTimeLong

  formatTimeLong = koji.formatTimeLong

  

+ def formatTimestampDifference(start_ts, end_ts):

+     diff = end_ts - start_ts

+     seconds = diff % 60

+     diff = diff // 60

+     minutes = diff % 60

+     diff = diff // 60

+     hours = diff

+     return "%d:%02d:%02d" % (hours, minutes, seconds)

+ 

  def formatDep(name, version, flags):

      """Format dependency information into

      a human-readable format.  Copied from

Parsing the formatted time seems clunky and awkward when getTaskInfo returns these as timestamps also.

In the new formatTimeDifference function, you're dividing by 100 successively to get minutes and hours. That should be 60 unless I'm missing something. Also I think you can skip subtracting the seconds and minutes and instead just use integer division.

rebased onto a2a7983f36bcc74ca0747723ef19ac71dca02ea0

3 years ago

Updated - you're right. I've must been in some caffeine insufficiency state. (Maybe connected to that I wasn't able to easily determine some task length in the moment, so I've created this patch :-))

Traceback (most recent call last):
  File "/usr/share/koji-web/scripts/wsgi_publisher.py", line 378, in handle_request
    result = func(environ, **data)
  File "/usr/share/koji-web/scripts/index.py", line 694, in taskinfo
    return _genHTML(environ, 'taskinfo.chtml')
  File "/usr/share/koji-web/lib/kojiweb/util.py", line 156, in _genHTML
    return tmpl_inst.respond()
  File "taskinfo_chtml.py", line 1141, in respond
NameMapper.NotFound: cannot find 'end_ts'

Looks like the value is not set for open tasks.

rebased onto 8f82c3b

3 years ago

Fixed + added descriptions.

Traceback (most recent call last):
  File "/home/mike/Devel/koji/koji/www/kojiweb/wsgi_publisher.py", line 378, in handle_request
    result = func(environ, **data)
  File "/home/mike/Devel/koji/koji/www/kojiweb/index.py", line 694, in taskinfo
    return _genHTML(environ, 'taskinfo.chtml')
  File "/home/mike/Devel/koji/koji/www/lib/kojiweb/util.py", line 154, in _genHTML
    return tmpl_inst.respond().encode('utf-8', 'replace')
  File "taskinfo_chtml.py", line 1140, in respond
AttributeError: 'datetime.datetime' object has no attribute 'timestamp'

This appears to be a python3-ism. Since we're only doing this with now(), it's probably easiest to just use time.time() instead.

2 new commits added

  • remove unneeded import
  • use time.time() for current timestamp
3 years ago

Cherry-picked + removed datetime import.

Commit f2eaa6c fixes this pull-request

Pull-Request has been merged by mikem

3 years ago