-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
51 lines (42 loc) · 1.13 KB
/
type.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
package crawler
import (
"context"
"github.com/hopeio/cherry/utils/scheduler/engine"
)
type Request = engine.Task[string]
type TaskMeta = engine.TaskMeta[string]
type TaskFunc = engine.TaskFunc[string]
func NewRequest(key string, kind engine.Kind, taskFunc TaskFunc) *Request {
return &Request{
TaskMeta: TaskMeta{
Key: key,
Kind: kind,
},
TaskFunc: taskFunc,
}
}
type Config = engine.Config[string]
type Engine = engine.Engine[string]
func NewEngine(workerCount uint) *engine.Engine[string] {
return engine.NewEngine[string](workerCount)
}
type HandleFunc func(ctx context.Context, url string) ([]*Request, error)
func NewUrlRequest(url string, handleFunc HandleFunc) *Request {
if handleFunc == nil {
return nil
}
return &Request{TaskMeta: TaskMeta{Key: url}, TaskFunc: func(ctx context.Context) ([]*Request, error) {
return handleFunc(ctx, url)
}}
}
func NewUrlKindRequest(url string, kind engine.Kind, handleFunc HandleFunc) *Request {
if handleFunc == nil {
return nil
}
req := NewUrlRequest(url, handleFunc)
req.SetKind(kind)
return req
}
func NewTaskMeta(key string) TaskMeta {
return TaskMeta{Key: key}
}