File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 22
22
<thead >
23
23
<tr >
24
24
<th >{!! Html:: columnSort (' Description' , ' description' ) ! !} </th >
25
- <th >Average Runtime</th >
26
- <th >Last Run</th >
25
+ <th >{!! Html :: columnSort ( ' Average Runtime' , ' average_runtime ' ) ! !} </th >
26
+ <th >{!! Html :: columnSort ( ' Last Run' , ' last_ran_at ' ) ! !} </th >
27
27
<th >Next Run</th >
28
28
<th class =" uk-text-center" >Execute</th >
29
29
</tr >
85
85
</span >
86
86
</div >
87
87
{{ $tasks -> links (' totem::partials.pagination' )} }
88
- @stop
88
+ @stop
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ public function index()
38
38
->builder ()
39
39
->sortableBy ([
40
40
'description ' ,
41
+ 'last_ran_at ' ,
42
+ 'average_runtime ' ,
41
43
], ['description ' =>'asc ' ])
42
44
->when (request ('q ' ), function ($ query ) {
43
45
$ query ->where ('description ' , 'LIKE ' , '% ' .request ('q ' ).'% ' );
Original file line number Diff line number Diff line change 3
3
namespace Studio \Totem \Repositories ;
4
4
5
5
use Studio \Totem \Task ;
6
+ use Studio \Totem \Result ;
6
7
use Studio \Totem \Events \Created ;
7
8
use Studio \Totem \Events \Deleted ;
8
9
use Studio \Totem \Events \Updated ;
14
15
use Studio \Totem \Events \Deactivated ;
15
16
use Illuminate \Support \Facades \Cache ;
16
17
use Illuminate \Support \Facades \Artisan ;
18
+ use Illuminate \Database \Eloquent \Builder ;
17
19
use Studio \Totem \Contracts \TaskInterface ;
18
20
19
21
class EloquentTaskRepository implements TaskInterface
@@ -23,9 +25,19 @@ class EloquentTaskRepository implements TaskInterface
23
25
*
24
26
* @return Task
25
27
*/
26
- public function builder ()
28
+ public function builder () : Builder
27
29
{
28
- return new Task ;
30
+ $ result = new Result ;
31
+
32
+ return (new Task )->select ('tasks.* ' )
33
+ ->selectSub (
34
+ $ result ->getLastRun (),
35
+ 'last_ran_at '
36
+ )
37
+ ->selectSub (
38
+ $ result ->getAverageRunTime (),
39
+ 'average_runtime '
40
+ );
29
41
}
30
42
31
43
/**
Original file line number Diff line number Diff line change 2
2
3
3
namespace Studio \Totem ;
4
4
5
+ use Illuminate \Support \Facades \DB ;
6
+ use Illuminate \Database \Query \Builder ;
7
+
5
8
class Result extends TotemModel
6
9
{
7
10
protected $ table = 'task_results ' ;
@@ -19,4 +22,26 @@ public function task()
19
22
{
20
23
return $ this ->belongsTo (Task::class);
21
24
}
25
+
26
+ /**
27
+ * @return Builder
28
+ */
29
+ public function getLastRun () : Builder
30
+ {
31
+ return $ this ->select ('ran_at ' )
32
+ ->whereColumn ('task_id ' , 'tasks.id ' )
33
+ ->latest ()
34
+ ->limit (1 )
35
+ ->getQuery ();
36
+ }
37
+
38
+ /**
39
+ * @return Builder
40
+ */
41
+ public function getAverageRunTime () : Builder
42
+ {
43
+ return $ this ->select (DB ::raw ('avg(duration) ' ))
44
+ ->whereColumn ('task_id ' , 'tasks.id ' )
45
+ ->getQuery ();
46
+ }
22
47
}
You can’t perform that action at this time.
0 commit comments