-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (40 loc) · 1.17 KB
/
main.go
File metadata and controls
45 lines (40 loc) · 1.17 KB
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
40
41
42
43
44
45
package main
import (
"github.com/datasets-org/task-processor/storage"
"github.com/datasets-org/task-processor/managers"
"github.com/datasets-org/task-processor/processors"
"flag"
"github.com/datasets-org/task-processor/structs"
"time"
"math/rand"
"fmt"
"os"
"path"
)
func main() {
flag.Set("stderrthreshold", "INFO")
flag.Parse()
ms := storage.CreateSyncMapStorage()
//ms.Put("ID-0", `{"id": "ID-0", "task": {"operation": "dummy"}, "created": "2018-04-01T13:07:59.1234", "completed": false}`)
t := managers.Tasks{Storage: ms}
//t.Store(structs.Task{Id:"ID-0", Task: structs.TaskDefinition{Operation: "dummy"}})
dir, _ := os.Getwd()
path := path.Join(dir, "data")
t.Store(structs.Task{Id:"ID-0", Task: structs.TaskDefinition{Operation: "scan", Params: fmt.Sprintf(`{"fs": "local", "path": "%s"}`, path)}})
go taskCreator(&t)
processors.Reactor(&t)
}
func taskCreator(tasks *managers.Tasks) {
for {
var op string
if rand.Intn(10) > 3 {
op = "dummy"
} else {
op = "random"
}
tasks.Store(structs.Task{
Id: fmt.Sprintf("ID-%d", rand.Intn(100)),
Task: structs.TaskDefinition{Operation: op}})
time.Sleep(time.Duration(rand.Intn(5)) * time.Second)
}
}