Skip to content

Commit

Permalink
service: reduce cycling references, related with #475
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Sep 24, 2018
1 parent f741f53 commit 487beb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
8 changes: 4 additions & 4 deletions service/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type Event struct {
// Data holds the input parameters of event.
Data []*Parameter `hash:"name:4"`

// service is the event's service.
service *Service `hash:"-"`
// serviceName is the event's service's name.
serviceName string `hash:"-"`
}

// GetEvent returns event eventKey of service.
func (s *Service) GetEvent(eventKey string) (*Event, error) {
for _, event := range s.Events {
if event.Key == eventKey {
event.service = s
event.serviceName = s.Name
return event, nil
}
}
Expand All @@ -43,7 +43,7 @@ func (e *Event) RequireData(eventData map[string]interface{}) error {
if len(warnings) > 0 {
return &InvalidEventDataError{
EventKey: e.Key,
ServiceName: e.service.Name,
ServiceName: e.serviceName,
Warnings: warnings,
}
}
Expand Down
10 changes: 0 additions & 10 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,6 @@ func (s *Service) setOptions(options ...Option) error {

// fromService upgrades service s by setting a calculated ID and cross-referencing its child fields.
func (s *Service) fromService() *Service {
for _, event := range s.Events {
event.service = s
}
for _, task := range s.Tasks {
task.service = s
for _, output := range task.Outputs {
output.task = task
output.service = s
}
}
for _, dep := range s.Dependencies {
dep.service = s
}
Expand Down
28 changes: 14 additions & 14 deletions service/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Task struct {
// Outputs are the definition of the execution results of task.
Outputs []*Output `hash:"name:5"`

// service is the task's service.
service *Service `hash:"-"`
// serviceName is the task's service's name.
serviceName string `hash:"-"`
}

// Output describes task output.
Expand All @@ -35,18 +35,18 @@ type Output struct {
// Data holds the output parameters of a task output.
Data []*Parameter `hash:"name:4"`

// task is the output's task.
task *Task `hash:"-"`
// taskKey is the output's task's key.
taskKey string `hash:"-"`

// service is the output's service.
service *Service `hash:"-"`
// serviceName is the output's service's name.
serviceName string `hash:"-"`
}

// GetTask returns task taskKey of service.
func (s *Service) GetTask(taskKey string) (*Task, error) {
for _, task := range s.Tasks {
if task.Key == taskKey {
task.service = s
task.serviceName = s.Name
return task, nil
}
}
Expand All @@ -66,7 +66,7 @@ func (t *Task) GetInputParameter(inputKey string) (*Parameter, error) {
return nil, &TaskInputNotFoundError{
TaskKey: t.Key,
TaskInputKey: inputKey,
ServiceName: t.service.Name,
ServiceName: t.serviceName,
}
}

Expand All @@ -81,7 +81,7 @@ func (t *Task) RequireInputs(taskInputs map[string]interface{}) error {
if len(warnings) > 0 {
return &InvalidTaskInputError{
TaskKey: t.Key,
ServiceName: t.service.Name,
ServiceName: t.serviceName,
Warnings: warnings,
}
}
Expand All @@ -92,15 +92,15 @@ func (t *Task) RequireInputs(taskInputs map[string]interface{}) error {
func (t *Task) GetOutput(outputKey string) (*Output, error) {
for _, output := range t.Outputs {
if output.Key == outputKey {
output.task = t
output.service = t.service
output.taskKey = t.Key
output.serviceName = t.serviceName
return output, nil
}
}
return nil, &TaskOutputNotFoundError{
TaskKey: t.Key,
TaskOutputKey: outputKey,
ServiceName: t.service.Name,
ServiceName: t.serviceName,
}
}

Expand All @@ -114,9 +114,9 @@ func (o *Output) RequireData(outputData map[string]interface{}) error {
warnings := o.ValidateData(outputData)
if len(warnings) > 0 {
return &InvalidTaskOutputError{
TaskKey: o.task.Key,
TaskKey: o.taskKey,
TaskOutputKey: o.Key,
ServiceName: o.service.Name,
ServiceName: o.serviceName,
Warnings: warnings,
}
}
Expand Down

0 comments on commit 487beb3

Please sign in to comment.