Skip to content

Commit

Permalink
Move templated tasks to task dir from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Oct 2, 2017
1 parent af8c600 commit 5a5ce59
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 25 additions & 25 deletions services/load/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ 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()

tasksDir := s.config.tasksDir()

files, err := ioutil.ReadDir(tasksDir)
if err != nil {
return nil, err
return nil, nil, err
}

for _, file := range files {
Expand All @@ -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
}
Expand All @@ -98,18 +101,17 @@ 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()

templatesDir := s.config.templatesDir()

files, err := ioutil.ReadDir(templatesDir)
if err != nil {
return nil, nil, err
return nil, err
}

for _, file := range files {
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down

0 comments on commit 5a5ce59

Please sign in to comment.