-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.go
More file actions
50 lines (43 loc) · 784 Bytes
/
worker.go
File metadata and controls
50 lines (43 loc) · 784 Bytes
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
package main
import (
"time"
"github.com/k0kubun/pp"
)
func NewWork(url string, name string, typeOfWork string, period time.Duration) *Work {
return &Work{
URL: url,
Name: name,
Type: typeOfWork,
Period: period,
LastUpdate: time.Now(),
LastError: nil,
State: "created",
}
}
func (w *Work) Update() {
go func() {
w.LastUpdate = time.Now()
w.State = WorkUpdating
switch w.Type {
case WorkMatchType:
pp.Println("UPDATING MATCH!!!")
err := SaveDataForMatchWork(w)
if err != nil {
pp.Println(err)
w.LastError = err
break
}
w.LastError = nil
break
case WorkLeagueType:
err := SaveDataForLeagueWork(w)
if err != nil {
w.LastError = err
break
}
w.LastError = nil
break
}
w.State = WorkWaiting
}()
}