-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrigger_hook.go
More file actions
63 lines (52 loc) · 1.71 KB
/
trigger_hook.go
File metadata and controls
63 lines (52 loc) · 1.71 KB
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
package triggerhook
import (
"context"
"github.com/pvelx/triggerhook/contracts"
"github.com/pvelx/triggerhook/domain"
)
func New(
eventHandler contracts.EventHandlerInterface,
waitingService contracts.WaitingServiceInterface,
preloadingService contracts.PreloadingServiceInterface,
senderService contracts.SenderServiceInterface,
monitoringService contracts.MonitoringInterface,
) contracts.TriggerHookInterface {
return &triggerHook{
eventHandler: eventHandler,
waitingService: waitingService,
preloadingService: preloadingService,
senderService: senderService,
monitoringService: monitoringService,
}
}
type triggerHook struct {
waitingService contracts.WaitingServiceInterface
preloadingService contracts.PreloadingServiceInterface
senderService contracts.SenderServiceInterface
eventHandler contracts.EventHandlerInterface
monitoringService contracts.MonitoringInterface
}
// Deprecated
func (s *triggerHook) Delete(taskID string) error {
return s.waitingService.CancelIfExist(context.Background(), taskID)
}
// Deprecated
func (s *triggerHook) Create(task *domain.Task) error {
return s.preloadingService.AddNewTask(context.Background(), task)
}
func (s *triggerHook) DeleteCtx(ctx context.Context, taskID string) error {
return s.waitingService.CancelIfExist(ctx, taskID)
}
func (s *triggerHook) CreateCtx(ctx context.Context, task *domain.Task) error {
return s.preloadingService.AddNewTask(ctx, task)
}
func (s *triggerHook) Consume() contracts.TaskToSendInterface {
return s.senderService.Consume()
}
func (s *triggerHook) Run() error {
go s.preloadingService.Run()
go s.waitingService.Run()
go s.senderService.Run()
go s.monitoringService.Run()
return s.eventHandler.Run()
}