Skip to content

Commit

Permalink
Feature: Task Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Dec 14, 2023
1 parent 87f8928 commit f48435f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions datastore/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type taskRecord struct {
SubJobID string `db:"subjob_id"`
GPUs string `db:"gpus"`
IF string `db:"if_"`
Tags pq.StringArray `db:"tags"`
}

type jobRecord struct {
Expand Down Expand Up @@ -206,6 +207,7 @@ func (r taskRecord) toTask() (*tork.Task, error) {
SubJob: subjob,
GPUs: r.GPUs,
If: r.IF,
Tags: r.Tags,
}, nil
}

Expand Down Expand Up @@ -415,12 +417,13 @@ func (ds *PostgresDatastore) CreateTask(ctx context.Context, t *tork.Task) error
files_, -- $33
registry, -- $34
gpus, -- $35
if_ -- $36
if_, -- $36
tags -- $37
)
values (
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,
$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,
$27,$28,$29,$30,$31,$32,$33,$34,$35,$36)`
$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37)`
_, err = ds.exec(q,
t.ID, // $1
t.JobID, // $2
Expand Down Expand Up @@ -458,6 +461,7 @@ func (ds *PostgresDatastore) CreateTask(ctx context.Context, t *tork.Task) error
registry, // $34
t.GPUs, // $35
t.If, // $36
pq.StringArray(t.Tags), // $37
)
if err != nil {
return errors.Wrapf(err, "error inserting task to the db")
Expand Down
2 changes: 2 additions & 0 deletions datastore/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestPostgresCreateAndGetTask(t *testing.T) {
Registry: &tork.Registry{Username: "me", Password: "secret"},
GPUs: "all",
If: "true",
Tags: []string{"tag1", "tag2"},
}
err = ds.CreateTask(ctx, &t1)
assert.NoError(t, err)
Expand All @@ -51,6 +52,7 @@ func TestPostgresCreateAndGetTask(t *testing.T) {
assert.Equal(t, "all", t2.GPUs)
assert.Equal(t, "true", t2.If)
assert.Nil(t, t2.Parallel)
assert.Equal(t, []string([]string{"tag1", "tag2"}), t2.Tags)
}

func TestPostgresCreateAndGetParallelTask(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion db/postgres/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ CREATE TABLE tasks (
subjob jsonb,
networks text[],
gpus text,
if_ text
if_ text,
tags text[]
);
CREATE INDEX idx_tasks_state ON tasks (state);
Expand Down
2 changes: 2 additions & 0 deletions input/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Task struct {
Each *Each `json:"each,omitempty" yaml:"each,omitempty"`
SubJob *SubJob `json:"subjob,omitempty" yaml:"subjob,omitempty"`
GPUs string `json:"gpus,omitempty" yaml:"gpus,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type SubJob struct {
Expand Down Expand Up @@ -185,6 +186,7 @@ func (i Task) toTask() *tork.Task {
Each: each,
SubJob: subjob,
GPUs: i.GPUs,
Tags: i.Tags,
}
}

Expand Down
2 changes: 2 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Task struct {
Each *EachTask `json:"each,omitempty"`
SubJob *SubJobTask `json:"subjob,omitempty"`
GPUs string `json:"gpus,omitempty"`
Tags []string `json:"tags,omitempty"`
}

type SubJobTask struct {
Expand Down Expand Up @@ -168,6 +169,7 @@ func (t *Task) Clone() *Task {
Description: t.Description,
SubJob: subjob,
GPUs: t.GPUs,
Tags: t.Tags,
}
}

Expand Down

0 comments on commit f48435f

Please sign in to comment.