Skip to content

Commit

Permalink
Persist DepStatus of tasks (woodpecker-ci#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszgyg authored and alexef committed Mar 14, 2023
1 parent a08a072 commit 1d4e59c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions server/model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion server/queue/persistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
25 changes: 9 additions & 16 deletions server/store/datastore/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,21 @@ 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()
if err != nil {
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 {
Expand All @@ -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")
}

0 comments on commit 1d4e59c

Please sign in to comment.