Skip to content

Commit

Permalink
Next execution
Browse files Browse the repository at this point in the history
Return next execution field in API and dashboard.
  • Loading branch information
Victor Castell committed Mar 12, 2019
1 parent 0e7c8cd commit 0435228
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 171 deletions.
284 changes: 142 additions & 142 deletions dkron/assets/assets_vfsdata.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions dkron/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/abronan/valkeyrie/store"
"github.com/sirupsen/logrus"
"github.com/victorcoder/dkron/cron"
"github.com/victorcoder/dkron/proto"
)

Expand Down Expand Up @@ -109,6 +110,9 @@ type Job struct {

// Computed job status
Status string `json:"status"`

// Computed next execution
Next time.Time `json:"next"`
}

func NewJobFromProto(in *proto.GetJobResponse) *Job {
Expand Down Expand Up @@ -260,6 +264,14 @@ func (j *Job) Unlock() error {
return nil
}

func (j *Job) GetNext() (time.Time, error) {
s, err := cron.Parse(j.Schedule)
if err != nil {
return time.Time{}, err
}
return s.Next(time.Now()), nil
}

func (j *Job) isRunnable() bool {
if j.Concurrency == ConcurrencyForbid {
j.Agent.RefreshJobStatus(j.Name)
Expand Down
15 changes: 14 additions & 1 deletion dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/abronan/valkeyrie/store/consul"
"github.com/abronan/valkeyrie/store/dynamodb"
"github.com/abronan/valkeyrie/store/etcd/v2"
"github.com/abronan/valkeyrie/store/etcd/v3"
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
"github.com/abronan/valkeyrie/store/redis"
"github.com/abronan/valkeyrie/store/zookeeper"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -275,6 +275,13 @@ func (s *Store) GetJobs(options *JobOptions) ([]*Job, error) {
job.Status = job.GetStatus()
}
}

n, err := job.GetNext()
if err != nil {
return nil, err
}
job.Next = n

jobs = append(jobs, &job)
}
return jobs, nil
Expand Down Expand Up @@ -306,6 +313,12 @@ func (s *Store) GetJobWithKVPair(name string, options *JobOptions) (*Job, *store
job.Status = job.GetStatus()
}

n, err := job.GetNext()
if err != nil {
return nil, nil, err
}
job.Next = n

return &job, res, nil
}

Expand Down
16 changes: 8 additions & 8 deletions dkron/templates/templates_vfsdata.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ require (
github.com/prometheus/procfs v0.0.0-20181129180645-aa55a523dc0a // indirect
github.com/russross/blackfriday v0.0.0-20180804101149-46c73eb196ba // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
github.com/sirupsen/logrus v1.2.0
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spf13/afero v0.0.0-20171008182726-e67d870304c4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec h1:6ncX5ko6B9L
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 h1:IYVb70m/qpJGjyZV2S4qbdSDnsMl+w9nsQ2iQedf1HI=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
Expand Down
54 changes: 34 additions & 20 deletions templates/jobs.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div class="input-group-addon"><i class="glyphicon glyphicon-search"></i></div>
<input type="text" class="form-control" placeholder="Filter" ng-model="searchJob">
<div class="input-group-addon">
<a href="#" data-toggle="modal" data-target="#jobTemplateModal" title="New"><i class="glyphicon glyphicon-plus"
aria-hidden="true"></i></a>
<a href="#" data-toggle="modal" data-target="#jobTemplateModal" title="New"><i
class="glyphicon glyphicon-plus" aria-hidden="true"></i></a>
</div>
</div>
</div>
Expand All @@ -22,6 +22,7 @@
<th>Success</th>
<th>Error</th>
<th>Last execution</th>
<th>Next execution</th>
<th>Status</th>
<th>Actions</th>
</tr>
Expand All @@ -34,8 +35,8 @@
<a href ng-click="prevPage()">« Prev</a>
</li>

<li ng-repeat="n in range(pagedItems.length, currentPage, currentPage + gap) " ng-class="{active: n == currentPage}"
ng-click="setPage()">
<li ng-repeat="n in range(pagedItems.length, currentPage, currentPage + gap) "
ng-class="{active: n == currentPage}" ng-click="setPage()">
<a href ng-bind="n + 1"></a>
</li>

Expand All @@ -52,39 +53,48 @@
<td ng-bind="job.schedule"></td>
<td ng-bind="job.success_count"></td>
<td ng-bind="job.error_count"></td>
<td ng-bind="(job.last_success > job.last_error ? job.last_success : job.last_error) | date:'yyyy-MM-dd HH:mm:ss Z'"></td>
<td
ng-bind="(job.last_success > job.last_error ? job.last_success : job.last_error) | date:'yyyy-MM-dd HH:mm:ss Z'">
</td>
<td ng-bind="job.next | date:'yyyy-MM-dd HH:mm:ss Z'"></td>
<td>
<i ng-class="job | statusClass" class="glyphicon"></i>
</td>
<td>
<a ng-href="#{{`{{ $index }}`}}-modal" data-toggle="modal" data-target="#{{`{{ $index }}`}}-modal" title="View">
<a ng-href="#{{`{{ $index }}`}}-modal" data-toggle="modal" data-target="#{{`{{ $index }}`}}-modal"
title="View">
<i class="glyphicon glyphicon-eye-open" aria-hidden="true"></i>
</a>
&nbsp;
<a href="#" ng-click="runJob(job.name)" ng-show="!running_{{`{{ $index }}`}}" title="Run"><i class="glyphicon glyphicon-play"
aria-hidden="true"></i></a>
<a href="#"><i class="glyphicon glyphicon-cog normal-right-spinner" ng-show="running_{{`{{ $index }}`}}"></i></a>
<a href="#" ng-click="runJob(job.name)" ng-show="!running_{{`{{ $index }}`}}" title="Run"><i
class="glyphicon glyphicon-play" aria-hidden="true"></i></a>
<a href="#"><i class="glyphicon glyphicon-cog normal-right-spinner"
ng-show="running_{{`{{ $index }}`}}"></i></a>
&nbsp;
<a href="#" ng-click="toggleJob(job.name)" title="Toggle"><i class="glyphicon glyphicon-pause" aria-hidden="true"></i></a>
<a href="#" ng-click="toggleJob(job.name)" title="Toggle"><i class="glyphicon glyphicon-pause"
aria-hidden="true"></i></a>
&nbsp;
<a href="#" data-toggle="modal" data-target="#{{`{{ $index }}`}}-modal-delete" ng-show="!deleting_{{`{{ $index }}`}}"
title="Delete"><i class="glyphicon glyphicon-trash" aria-hidden="true"></i></a>
<a href=""><i class="glyphicon glyphicon-cog normal-right-spinner" ng-show="deleting_{{`{{ $index }}`}}"></i></a>
<a href="#" data-toggle="modal" data-target="#{{`{{ $index }}`}}-modal-delete"
ng-show="!deleting_{{`{{ $index }}`}}" title="Delete"><i class="glyphicon glyphicon-trash"
aria-hidden="true"></i></a>
<a href=""><i class="glyphicon glyphicon-cog normal-right-spinner"
ng-show="deleting_{{`{{ $index }}`}}"></i></a>
</td>
</tr>
</tbody>
</table>

<!-- Modal Delete -->
<div ng-repeat="job in pagedItems[currentPage] | filter:searchJob" class="modal fade" id="{{`{{ $index }}`}}-modal-delete"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div ng-repeat="job in pagedItems[currentPage] | filter:searchJob" class="modal fade"
id="{{`{{ $index }}`}}-modal-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
Are you sure?
</div>
<div class="modal-footer">
<button class="btn btn-default" ng-click="deleteJob(job.name)" value="Delete" data-dismiss="modal">Confirm</button>
<button class="btn btn-default" ng-click="deleteJob(job.name)" value="Delete"
data-dismiss="modal">Confirm</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
Expand All @@ -97,15 +107,17 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel" ng-bind="'View ' + job.name"></h4>
</div>
<div class="modal-body" ng-init="jobJson=toJson(job)">
<textarea ui-codemirror ui-codemirror-opts="editorOptions" ng-model="jobJson"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button class="btn btn-default" ng-click="updateJob(jobJson)" value="update" data-dismiss="modal">Update</button>
<button class="btn btn-default" ng-click="updateJob(jobJson)" value="update"
data-dismiss="modal">Update</button>
</div>
</div>
</div>
Expand All @@ -116,15 +128,17 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel" ng-bind="'Create'"></h4>
</div>
<div class="modal-body">
<textarea ui-codemirror ui-codemirror-opts="editorOptions" ng-model="jobTemplateJson"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button class="btn btn-default" ng-click="createJob(jobTemplateJson)" value="Create" data-dismiss="modal">Create</button>
<button class="btn btn-default" ng-click="createJob(jobTemplateJson)" value="Create"
data-dismiss="modal">Create</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 0435228

Please sign in to comment.