util-go/time/scheduler/storage/memory.go
crusader 6b4beb77fb ing
2018-04-28 21:39:55 +09:00

36 lines
943 B
Go

package storage
// MemoryStorage is a memory task store
type MemoryStorage struct {
taskAttributes []*TaskAttribute
}
// NewMemoryStorage returns an instance of MemoryStorage.
func NewMemoryStorage() *MemoryStorage {
return &MemoryStorage{}
}
// Add adds a task to the memory store.
func (s *MemoryStorage) Add(taskAttribute *TaskAttribute) error {
s.taskAttributes = append(s.taskAttributes, taskAttribute)
return nil
}
// Fetch will return all tasks stored.
func (s *MemoryStorage) Fetch() ([]*TaskAttribute, error) {
return s.taskAttributes, nil
}
// Remove will remove task from store
func (s *MemoryStorage) Remove(taskAttribute *TaskAttribute) error {
var newTaskAttributes []*TaskAttribute
for _, eTaskAttribute := range s.taskAttributes {
if taskAttribute.Hash == eTaskAttribute.Hash {
continue
}
newTaskAttributes = append(newTaskAttributes, eTaskAttribute)
}
s.taskAttributes = newTaskAttributes
return nil
}