Skip to content

Commit

Permalink
Merge pull request #53 from whywaita/fix/49
Browse files Browse the repository at this point in the history
ListTarget do not return target that can not receive job
  • Loading branch information
whywaita authored May 26, 2021
2 parents b271d1d + d3859d5 commit 45449c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions pkg/datastore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ func (t *Target) CanReceiveJob() bool {
return true
}

// ListTargets get list of target that can receive job
func ListTargets(ctx context.Context, ds Datastore) ([]Target, error) {
targets, err := ds.ListTargets(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get targets from datastore: %w", err)
}

var result []Target

for _, t := range targets {
if t.CanReceiveJob() {
result = append(result, t)
}
}

return result, nil
}

// UpdateTargetStatus update datastore
func UpdateTargetStatus(ctx context.Context, ds Datastore, targetID uuid.UUID, newStatus TargetStatus, description string) error {
target, err := ds.GetTarget(ctx, targetID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (m *Manager) Loop(ctx context.Context) error {
func (m *Manager) do(ctx context.Context) error {
logger.Logf(true, "start runner manager")

targets, err := m.ds.ListTargets(ctx)
targets, err := datastore.ListTargets(ctx, m.ds)
if err != nil {
return fmt.Errorf("failed to get targets: %w", err)
}
Expand All @@ -86,7 +86,7 @@ func (m *Manager) do(ctx context.Context) error {
func (m *Manager) permissionCheck(ctx context.Context) error {
logger.Logf(true, "start checking initialize state")

targets, err := m.ds.ListTargets(ctx)
targets, err := datastore.ListTargets(ctx, m.ds)
if err != nil {
return fmt.Errorf("failed to get targets: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/web/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *targetCreateParam) toDS() datastore.Target {
func handleTargetList(w http.ResponseWriter, r *http.Request, ds datastore.Datastore) {
ctx := r.Context()

ts, err := ds.ListTargets(ctx)
ts, err := datastore.ListTargets(ctx, ds)
if err != nil {
logger.Logf(false, "failed to retrieve list of target: %+v", err)
outputErrorMsg(w, http.StatusInternalServerError, "datastore read error")
Expand Down

0 comments on commit 45449c9

Please sign in to comment.