From c46f72da093c5179701fa35527f5631a91b11ab2 Mon Sep 17 00:00:00 2001 From: Michael Desa Date: Mon, 2 Oct 2017 10:28:35 -0400 Subject: [PATCH] Move templated tasks to task dir from templates --- .../load/{templates => tasks}/another.yaml | 0 examples/load/{templates => tasks}/base.yaml | 0 .../load/{templates => tasks}/implicit.yaml | 0 examples/load/{templates => tasks}/other.json | 0 services/load/service.go | 50 +++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) rename examples/load/{templates => tasks}/another.yaml (100%) rename examples/load/{templates => tasks}/base.yaml (100%) rename examples/load/{templates => tasks}/implicit.yaml (100%) rename examples/load/{templates => tasks}/other.json (100%) diff --git a/examples/load/templates/another.yaml b/examples/load/tasks/another.yaml similarity index 100% rename from examples/load/templates/another.yaml rename to examples/load/tasks/another.yaml diff --git a/examples/load/templates/base.yaml b/examples/load/tasks/base.yaml similarity index 100% rename from examples/load/templates/base.yaml rename to examples/load/tasks/base.yaml diff --git a/examples/load/templates/implicit.yaml b/examples/load/tasks/implicit.yaml similarity index 100% rename from examples/load/templates/implicit.yaml rename to examples/load/tasks/implicit.yaml diff --git a/examples/load/templates/other.json b/examples/load/tasks/other.json similarity index 100% rename from examples/load/templates/other.json rename to examples/load/tasks/other.json diff --git a/services/load/service.go b/services/load/service.go index 40ab763e49..7253924697 100644 --- a/services/load/service.go +++ b/services/load/service.go @@ -68,9 +68,10 @@ func (s *Service) Close() error { return nil } -// TaskFiles gets a slice of all files with the .tick file extension +// taskFiles gets a slice of all files with the .tick file extension +// and any associated files with .json, .yml, and .yaml file extentions // in the configured task directory. -func (s *Service) taskFiles() (tickscripts []string, err error) { +func (s *Service) taskFiles() (tickscripts []string, taskFiles []string, err error) { s.mu.Lock() defer s.mu.Unlock() @@ -78,7 +79,7 @@ func (s *Service) taskFiles() (tickscripts []string, err error) { files, err := ioutil.ReadDir(tasksDir) if err != nil { - return nil, err + return nil, nil, err } for _, file := range files { @@ -90,6 +91,8 @@ func (s *Service) taskFiles() (tickscripts []string, err error) { switch ext := filepath.Ext(filename); ext { case ".tick": tickscripts = append(tickscripts, filepath.Join(tasksDir, filename)) + case ".yml", ".json", ".yaml": + taskFiles = append(taskFiles, filepath.Join(tasksDir, filename)) default: continue } @@ -98,10 +101,9 @@ func (s *Service) taskFiles() (tickscripts []string, err error) { return } -// TemplateFiles gets a slice of all files with the .tick file extension -// and any associated files with .json, .yml, and .yaml file extentions +// templateFiles gets a slice of all files with the .tick file extension // in the configured template directory. -func (s *Service) templateFiles() (tickscripts []string, tmplVars []string, err error) { +func (s *Service) templateFiles() (tickscripts []string, err error) { s.mu.Lock() defer s.mu.Unlock() @@ -109,7 +111,7 @@ func (s *Service) templateFiles() (tickscripts []string, tmplVars []string, err files, err := ioutil.ReadDir(templatesDir) if err != nil { - return nil, nil, err + return nil, err } for _, file := range files { @@ -121,8 +123,6 @@ func (s *Service) templateFiles() (tickscripts []string, tmplVars []string, err switch ext := filepath.Ext(filename); ext { case ".tick": tickscripts = append(tickscripts, filepath.Join(templatesDir, filename)) - case ".yml", ".json", ".yaml": - tmplVars = append(tmplVars, filepath.Join(templatesDir, filename)) default: continue } @@ -180,16 +180,16 @@ func (s *Service) load() error { return nil } - s.diag.Debug("loading tasks") - err := s.loadTasks() + s.diag.Debug("loading templates") + err := s.loadTemplates() if err != nil && !os.IsNotExist(err) { - return fmt.Errorf("failed to load tasks: %v", err) + return err } - s.diag.Debug("loading templates") - err = s.loadTemplates() + s.diag.Debug("loading tasks") + err = s.loadTasks() if err != nil && !os.IsNotExist(err) { - return err + return fmt.Errorf("failed to load tasks: %v", err) } s.diag.Debug("loading handlers") @@ -202,18 +202,25 @@ func (s *Service) load() error { } func (s *Service) loadTasks() error { - files, err := s.taskFiles() + ticks, templateTasks, err := s.taskFiles() if err != nil { return err } - for _, f := range files { + for _, f := range ticks { s.diag.Loading("task", f) if err := s.loadTask(f); err != nil { return fmt.Errorf("failed to load file %s: %s", f, err.Error()) } } + for _, v := range templateTasks { + s.diag.Loading("template task", v) + if err := s.loadVars(v); err != nil { + return fmt.Errorf("failed to load file %s: %s", v, err.Error()) + } + } + return nil } @@ -269,7 +276,7 @@ func (s *Service) loadTask(f string) error { } func (s *Service) loadTemplates() error { - files, vars, err := s.templateFiles() + files, err := s.templateFiles() if err != nil { return err } @@ -280,13 +287,6 @@ func (s *Service) loadTemplates() error { return fmt.Errorf("failed to load file %s: %s", f, err.Error()) } } - - for _, v := range vars { - s.diag.Loading("task-vars", v) - if err := s.loadVars(v); err != nil { - return fmt.Errorf("failed to load file %s: %s", v, err.Error()) - } - } return nil }