-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoter.go
90 lines (75 loc) · 2.08 KB
/
remoter.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
86
87
88
89
90
// author: wsfuyibing <websearch@163.com>
// date: 2023-02-03
package rabbitmq
import (
"context"
"fmt"
"github.com/fuyibing/gmd/app/md/base"
"github.com/fuyibing/log/v8"
"github.com/fuyibing/util/v8/process"
"sync"
)
type (
// Remoter
// struct for aliyun mns remoter.
Remoter struct {
mu *sync.RWMutex
name string
processor process.Processor
}
)
func NewRemoter() *Remoter {
o := (&Remoter{}).init()
return o
}
func (o *Remoter) Build(_ context.Context, _ *base.Task) (err error) { return fmt.Errorf("undefined") }
func (o *Remoter) BuildById(_ context.Context, _ int) (err error) { return fmt.Errorf("undefined") }
func (o *Remoter) Destroy(_ context.Context, _ *base.Task) (err error) {
return fmt.Errorf("undefined")
}
func (o *Remoter) DestroyById(_ context.Context, _ int) (err error) { return fmt.Errorf("undefined") }
func (o *Remoter) Processor() process.Processor { return o.processor }
// /////////////////////////////////////////////////////////////
// Event methods
// /////////////////////////////////////////////////////////////
func (o *Remoter) onAfter(ctx context.Context) (ignored bool) {
log.Infof("%s: processor stopped", o.name)
return
}
func (o *Remoter) onBefore(_ context.Context) (ignored bool) {
log.Infof("%s: start processor", o.name)
return
}
func (o *Remoter) onCaller(ctx context.Context) (ignored bool) {
for {
select {
case <-ctx.Done():
return
}
}
}
func (o *Remoter) onCallerAfter(_ context.Context) (ignored bool) {
return
}
func (o *Remoter) onCallerBefore(_ context.Context) (ignored bool) {
return
}
func (o *Remoter) onPanic(ctx context.Context, v interface{}) {
log.Panicfc(ctx, "%s: %v", o.name, v)
}
// /////////////////////////////////////////////////////////////
// Construct method
// /////////////////////////////////////////////////////////////
func (o *Remoter) init() *Remoter {
o.name = "rabbitmq-remoter"
o.processor = process.New(o.name).After(
o.onAfter,
).Before(
o.onBefore,
).Callback(
o.onCallerBefore,
o.onCaller,
o.onCallerAfter,
).Panic(o.onPanic)
return o
}