-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueuerListener.go
More file actions
44 lines (36 loc) · 1.16 KB
/
queuerListener.go
File metadata and controls
44 lines (36 loc) · 1.16 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
package queuer
import (
"fmt"
"github.com/siherrmann/queuer/helper"
"github.com/siherrmann/queuer/model"
)
// ListenForJobInsert listens for job insert events and notifies the provided function when a job is added.
func (q *Queuer) ListenForJobUpdate(notifyFunction func(data *model.Job)) error {
if q == nil || q.ctx == nil {
return helper.NewError("queuer check", fmt.Errorf("cannot listen with uninitialized or not running Queuer"))
}
outerReady := make(chan struct{})
ready := make(chan struct{})
go func() {
close(outerReady)
q.jobUpdateListener.Listen(q.ctx, ready, notifyFunction)
}()
<-ready
<-outerReady
return nil
}
// ListenForJobInsert listens for job insert events and notifies the provided function when a job is added.
func (q *Queuer) ListenForJobDelete(notifyFunction func(data *model.Job)) error {
if q == nil || q.ctx == nil {
return helper.NewError("queuer check", fmt.Errorf("cannot listen with uninitialized or not running Queuer"))
}
outerReady := make(chan struct{})
ready := make(chan struct{})
go func() {
close(outerReady)
q.jobDeleteListener.Listen(q.ctx, ready, notifyFunction)
}()
<-ready
<-outerReady
return nil
}