Skip to content

Commit

Permalink
feat(tasks): add description field to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed May 8, 2019
1 parent 5f21b4a commit c4d3a84
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5840,7 +5840,10 @@ components:
description: The name of the organization that owns this Task.
type: string
name:
description: A description of the task.
description: The name of the task.
type: string
description:
descripton: An optional description of the task.
type: string
status:
description: The current status of the task. When updated to 'inactive', cancels all queued jobs of this task.
Expand Down
6 changes: 5 additions & 1 deletion http/task_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
{
ID: 1,
Name: "task1",
Description: "A little Task",
OrganizationID: 1,
Organization: "test",
AuthorizationID: 0x100,
Expand Down Expand Up @@ -137,7 +138,8 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
},
"id": "0000000000000001",
"name": "task1",
"labels": [
"description": "A little Task",
"labels": [
{
"id": "fc3dc670a4be9b9a",
"name": "label",
Expand Down Expand Up @@ -445,6 +447,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
return &platform.Task{
ID: 1,
Name: "task1",
Description: "Brand New Task",
OrganizationID: 1,
Organization: "test",
AuthorizationID: 0x100,
Expand All @@ -468,6 +471,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
},
"id": "0000000000000001",
"name": "task1",
"description": "Brand New Task",
"labels": [],
"orgID": "0000000000000001",
"org": "test",
Expand Down
1 change: 1 addition & 0 deletions kv/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ func (s *Service) createTask(ctx context.Context, tx Tx, tc influxdb.TaskCreate)
Organization: org.Name,
AuthorizationID: auth.Identifier(),
Name: opt.Name,
Description: tc.Description,
Status: tc.Status,
Flux: tc.Flux,
Every: opt.Every.String(),
Expand Down
23 changes: 15 additions & 8 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Task struct {
Organization string `json:"org"`
AuthorizationID ID `json:"authorizationID"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Status string `json:"status"`
Flux string `json:"flux"`
Every string `json:"every,omitempty"`
Expand Down Expand Up @@ -133,6 +134,7 @@ type TaskService interface {
// TaskCreate is the set of values to create a task.
type TaskCreate struct {
Flux string `json:"flux"`
Description string `json:description,omitempty`
Status string `json:"status,omitempty"`
OrganizationID ID `json:"orgID,omitempty"`
Organization string `json:"org,omitempty"`
Expand All @@ -153,8 +155,9 @@ func (t TaskCreate) Validate() error {

// TaskUpdate represents updates to a task. Options updates override any options set in the Flux field.
type TaskUpdate struct {
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Description string `json:"description,omitempty"`

// LatestCompleted us to set latest completed on startup to skip task catchup
LatestCompleted *string `json:"-"`
Expand All @@ -169,9 +172,10 @@ type TaskUpdate struct {
func (t *TaskUpdate) UnmarshalJSON(data []byte) error {
// this is a type so we can marshal string into durations nicely
jo := struct {
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Name string `json:"name,omitempty"`
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`

// Cron is a cron style time schedule that can be used in place of Every.
Cron string `json:"cron,omitempty"`
Expand All @@ -195,6 +199,7 @@ func (t *TaskUpdate) UnmarshalJSON(data []byte) error {
return err
}
t.Options.Name = jo.Name
t.Description = jo.Description
t.Options.Cron = jo.Cron
t.Options.Every = jo.Every
if jo.Offset != nil {
Expand All @@ -212,9 +217,10 @@ func (t *TaskUpdate) UnmarshalJSON(data []byte) error {

func (t TaskUpdate) MarshalJSON() ([]byte, error) {
jo := struct {
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Name string `json:"name,omitempty"`
Flux *string `json:"flux,omitempty"`
Status *string `json:"status,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`

// Cron is a cron style time schedule that can be used in place of Every.
Cron string `json:"cron,omitempty"`
Expand All @@ -234,6 +240,7 @@ func (t TaskUpdate) MarshalJSON() ([]byte, error) {
jo.Name = t.Options.Name
jo.Cron = t.Options.Cron
jo.Every = t.Options.Every
jo.Description = t.Description
if t.Options.Offset != nil {
offset := *t.Options.Offset
jo.Offset = &offset
Expand Down

0 comments on commit c4d3a84

Please sign in to comment.