1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

Persist DepStatus of tasks (#1610)

This commit is contained in:
Lukasz 2023-03-11 01:58:28 +01:00 committed by GitHub
parent f1f722645c
commit dc90f97524
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")
}