mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Merge pull request #2486 from hashicorp/b-periodic-state
Fix periodic job state
This commit is contained in:
@@ -878,7 +878,15 @@ func (s *StateStore) EvalsByJob(ws memdb.WatchSet, jobID string) ([]*structs.Eva
|
||||
if raw == nil {
|
||||
break
|
||||
}
|
||||
out = append(out, raw.(*structs.Evaluation))
|
||||
|
||||
e := raw.(*structs.Evaluation)
|
||||
|
||||
// Filter non-exact matches
|
||||
if e.JobID != jobID {
|
||||
continue
|
||||
}
|
||||
|
||||
out = append(out, e)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -1619,9 +1627,16 @@ func (s *StateStore) getJobStatus(txn *memdb.Txn, job *structs.Job, evalDelete b
|
||||
}
|
||||
|
||||
hasEval := false
|
||||
for eval := evals.Next(); eval != nil; eval = evals.Next() {
|
||||
for raw := evals.Next(); raw != nil; raw = evals.Next() {
|
||||
e := raw.(*structs.Evaluation)
|
||||
|
||||
// Filter non-exact matches
|
||||
if e.JobID != job.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
hasEval = true
|
||||
if !eval.(*structs.Evaluation).TerminalStatus() {
|
||||
if !e.TerminalStatus() {
|
||||
return structs.JobStatusPending, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
@@ -494,6 +495,60 @@ func TestStateStore_UpdateUpsertJob_Job(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateStore_UpdateUpsertJob_PeriodicJob(t *testing.T) {
|
||||
state := testStateStore(t)
|
||||
job := mock.PeriodicJob()
|
||||
|
||||
// Create a watchset so we can test that upsert fires the watch
|
||||
ws := memdb.NewWatchSet()
|
||||
_, err := state.JobByID(ws, job.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %v", err)
|
||||
}
|
||||
|
||||
if err := state.UpsertJob(1000, job); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Create a child and an evaluation
|
||||
job2 := job.Copy()
|
||||
job2.Periodic = nil
|
||||
job2.ID = fmt.Sprintf("%v/%s-1490635020", job.ID, structs.PeriodicLaunchSuffix)
|
||||
err = state.UpsertJob(1001, job2)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
eval := mock.Eval()
|
||||
eval.JobID = job2.ID
|
||||
err = state.UpsertEvals(1002, []*structs.Evaluation{eval})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
job3 := job.Copy()
|
||||
job3.TaskGroups[0].Tasks[0].Name = "new name"
|
||||
err = state.UpsertJob(1003, job3)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if !watchFired(ws) {
|
||||
t.Fatalf("bad")
|
||||
}
|
||||
|
||||
ws = memdb.NewWatchSet()
|
||||
out, err := state.JobByID(ws, job.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if s, e := out.Status, structs.JobStatusRunning; s != e {
|
||||
t.Fatalf("got status %v; want %v", s, e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This test ensures that UpsertJob creates the EphemeralDisk is a job doesn't have
|
||||
// one and clear out the task's disk resource asks
|
||||
// COMPAT 0.4.1 -> 0.5
|
||||
|
||||
Reference in New Issue
Block a user