Skip to content

Commit

Permalink
Adding delete by glob
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Apr 1, 2016
1 parent 3cdbea3 commit d14eeeb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions services/task_store/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ func (ts *Service) Save(task *rawTask) error {
return err
}

func (ts *Service) Delete(name string) error {

func (ts *Service) deleteTask(name string) error {
ts.TaskMaster.StopTask(name)

return ts.db.Update(func(tx *bolt.Tx) error {
tb := tx.Bucket(tasksBucket)
if tb != nil {
Expand All @@ -544,6 +544,30 @@ func (ts *Service) Delete(name string) error {
})
}

func (ts *Service) Delete(pattern string) error {
rawTasks, err := ts.FindTasks(func(taskName string) (bool, error) {
matched, err := filepath.Match(pattern, taskName)
if err != nil {
return false, err
}

return matched, nil
})

if err != nil {
return nil
}

for _, rawTask := range rawTasks {
err = ts.deleteTask(rawTask.Name)
if err != nil {
return err
}
}

return nil
}

func (ts *Service) LoadRaw(name string) (*rawTask, error) {
var data []byte
err := ts.db.View(func(tx *bolt.Tx) error {
Expand Down

0 comments on commit d14eeeb

Please sign in to comment.