forked from rakanalh/scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.go
39 lines (33 loc) · 929 Bytes
/
memory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package storage
// MemoryStorage is a memory task store
type MemoryStorage struct {
tasks []TaskAttributes
}
// NewMemoryStorage returns an instance of MemoryStorage.
func NewMemoryStorage() *MemoryStorage {
return &MemoryStorage{}
}
// Add adds a task to the memory store.
func (memStore *MemoryStorage) Add(task TaskAttributes) error {
memStore.tasks = append(memStore.tasks, task)
return nil
}
// Fetch will return all tasks stored.
func (memStore *MemoryStorage) Fetch() ([]TaskAttributes, error) {
return memStore.tasks, nil
}
// Remove will remove task from store
func (memStore *MemoryStorage) Remove(task TaskAttributes) error {
var newTasks []TaskAttributes
for _, existingTask := range memStore.tasks {
if task.Hash == existingTask.Hash {
continue
}
newTasks = append(newTasks, existingTask)
}
memStore.tasks = newTasks
return nil
}
func (memStore *MemoryStorage) Close() error {
return nil
}