Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: reduce cycling refs #491

Merged
merged 2 commits into from Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions service/event.go
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
Expand Up @@ -126,16 +126,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
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