Persist DepStatus of tasks (#1610) (#1625)

backport #1610 to the `release/v0.15` branch

Co-authored-by: Lukasz <106734180+lukaszgyg@users.noreply.github.com>
This commit is contained in:
Alex Eftimie 2023-03-15 15:32:53 +01:00 committed by GitHub
parent a08a07206a
commit 653e68fc39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 17 deletions

View file

@ -28,6 +28,7 @@ type Task struct {
Labels map[string]string `xorm:"json 'task_labels'"`
Dependencies []string `xorm:"json 'task_dependencies'"`
RunOn []string `xorm:"json 'task_run_on'"`
DepStatus map[string]string `xorm:"json 'task_dep_status'"`
}
// TableName return database table name for xorm

View file

@ -36,7 +36,7 @@ func WithTaskStore(q Queue, s model.TaskStore) Queue {
Labels: task.Labels,
Dependencies: task.Dependencies,
RunOn: task.RunOn,
DepStatus: make(map[string]string),
DepStatus: task.DepStatus,
})
}
if err := q.PushAtOnce(context.Background(), toEnqueue); err != nil {
@ -58,6 +58,7 @@ func (q *persistentQueue) Push(c context.Context, task *Task) error {
Labels: task.Labels,
Dependencies: task.Dependencies,
RunOn: task.RunOn,
DepStatus: task.DepStatus,
}); err != nil {
return err
}
@ -80,6 +81,7 @@ func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*Task) error {
Labels: task.Labels,
Dependencies: task.Dependencies,
RunOn: task.RunOn,
DepStatus: task.DepStatus,
}); err != nil {
return err
}

View file

@ -27,9 +27,10 @@ func TestTaskList(t *testing.T) {
defer closer()
assert.NoError(t, store.TaskInsert(&model.Task{
ID: "some_random_id",
Data: []byte("foo"),
Labels: map[string]string{"foo": "bar"},
ID: "some_random_id",
Data: []byte("foo"),
Labels: map[string]string{"foo": "bar"},
DepStatus: map[string]string{"test": "dep"},
}))
list, err := store.TaskList()
@ -37,16 +38,10 @@ func TestTaskList(t *testing.T) {
t.Error(err)
return
}
if got, want := len(list), 1; got != want {
t.Errorf("Want %d task, got %d", want, got)
return
}
if got, want := list[0].ID, "some_random_id"; got != want {
t.Errorf("Want task id %s, got %s", want, got)
}
if got, want := list[0].Data, "foo"; string(got) != want {
t.Errorf("Want task data %s, got %s", want, string(got))
}
assert.Len(t, list, 1, "Expected one task in list")
assert.Equal(t, "some_random_id", list[0].ID)
assert.Equal(t, "foo", string(list[0].Data))
assert.EqualValues(t, map[string]string{"test": "dep"}, list[0].DepStatus)
err = store.TaskDelete("some_random_id")
if err != nil {
@ -59,7 +54,5 @@ func TestTaskList(t *testing.T) {
t.Error(err)
return
}
if got, want := len(list), 0; got != want {
t.Errorf("Want empty task list after delete")
}
assert.Len(t, list, 0, "Want empty task list after delete")
}