From c7fed71a3f9c6e4a05af23454984c51ec50ac0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=CC=87lker=20Go=CC=88ktug=CC=86=20O=CC=88ztu=CC=88rk?= Date: Mon, 24 Sep 2018 07:45:07 +0300 Subject: [PATCH] service: reduce cycling references, related with #475 --- service/event.go | 8 ++++---- service/service.go | 10 ---------- service/task.go | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/service/event.go b/service/event.go index 9f6e99b93..e09589d8d 100644 --- a/service/event.go +++ b/service/event.go @@ -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 } } @@ -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, } } diff --git a/service/service.go b/service/service.go index 258e708d0..1ec054228 100644 --- a/service/service.go +++ b/service/service.go @@ -130,16 +130,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 } diff --git a/service/task.go b/service/task.go index 6042d8be4..9502bf7e2 100644 --- a/service/task.go +++ b/service/task.go @@ -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. @@ -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 } } @@ -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, } } @@ -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, } } @@ -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, } } @@ -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, } }