/
phashTask.go
50 lines (41 loc) · 952 Bytes
/
phashTask.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
package multi
import (
"os"
"time"
"github.com/gotgo/fw/logging"
"github.com/gotgo/fw/me"
cphash "github.com/kavu/go-phash"
)
func PHashTaskIn(filepath string) interface{} {
return filepath
}
func PHashTaskOut(out interface{}) uint64 {
return out.(uint64)
}
type PHashTask struct {
Log logging.Logger
}
func (p *PHashTask) Run(input interface{}) (interface{}, error) {
filepath, ok := input.(string)
if !ok {
panic("wrong type")
}
fi, err := os.Stat(filepath)
if err != nil {
me.LogError(p.Log, "failed with path "+filepath, err)
return nil, err
}
if fi.Size() == int64(0) {
me.LogInform(p.Log, "size is zero sleeping.....for 5 seconds for "+filepath)
time.Sleep(time.Second * 5)
}
if fi.Size() == int64(0) {
me.LogInform(p.Log, "still size zero")
return nil, me.NewErr("file is size zero")
}
hash, err := cphash.ImageHashDCT(filepath)
return hash, err
}
func (p *PHashTask) Name() string {
return "phash"
}