-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (67 loc) · 1.27 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"testing"
"time"
)
type Metadata struct {
SuccessCount uint
}
type RemoteProperties struct {
Headers http.Header `json:"headers"`
Url string `json:"url"`
ExpectedResponseCodes []int `json:"expected_response_codes"`
}
type JobsMap struct {
Jobs map[string]*Job
Lock sync.RWMutex
}
func NewJobsMap() *JobsMap {
return &JobsMap{
Jobs: map[string]*Job{},
Lock: sync.RWMutex{},
}
}
type JobCache interface {
GetAll() *JobsMap
Set(j *Job) error
}
type JobDB interface {
GetAll() ([]*Job, error)
}
type MockDBGetAll struct {
MockDB
response []*Job
}
func (d *MockDBGetAll) GetAll() ([]*Job, error) {
return d.response, nil
}
func parseTime(t *testing.T, value string) time.Time {
now, err := time.Parse("2006-Jan-02 15:04", value)
if err != nil {
t.Fatal(err)
}
return now
}
var _ JobDB = (*MemoryDB)(nil)
func main() {
mdb2b := NewMemoryDB()
c := NewLockFreeJobCache(mdb2b)
j := &Job{Metadata: Metadata{
SuccessCount: 0,
}}
j.Init(c)
c.Start()
j.Run(c)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
done := make(chan bool, 1)
fmt.Println("awaiting signal")
<-done
fmt.Println("exiting")
}