Skip to content
Snippets Groups Projects
Commit 005637e6 authored by Jonah Husson's avatar Jonah Husson
Browse files

Use added params

parent 0b716112
No related branches found
No related tags found
2 merge requests!21Release,!18Batched notification
......@@ -65,6 +65,8 @@ func TestImpl_InitCreator(t *testing.T) {
t.FailNow()
}
impl, err := StartNotifications(Params{
NotificationsPerBatch: 20,
NotificationRate: 30,
Address: "",
CertPath: "",
KeyPath: "",
......
......@@ -39,7 +39,6 @@ import (
)
const notificationsTag = "notificationData"
const maxNotifications = 20
// Function type definitions for the main operations (poll and notify)
type NotifyFunc func(int64, []*pb.NotificationData, *apns.ApnsComm, *firebase.FirebaseComm, *storage.Storage) error
......@@ -72,6 +71,7 @@ type Impl struct {
apnsClient *apns.ApnsComm
receivedNdf *uint32
roundStore sync.Map
maxNotifications int
ndfStopper Stopper
}
......@@ -114,6 +114,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
notifyFunc: notifyUser,
fcm: fbComm,
receivedNdf: &receivedNdf,
maxNotifications: params.NotificationsPerBatch,
}
if params.APNS.KeyPath == "" {
......@@ -157,6 +158,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
impl.inst = i
go impl.Cleaner()
go impl.Sender(params.NotificationRate)
return impl, nil
}
......@@ -376,15 +378,22 @@ func (nb *Impl) Cleaner() {
}
cleanTicker := time.NewTicker(time.Minute * 10)
sendTicker := time.NewTicker(30 * time.Second)
for {
select {
case <-cleanTicker.C:
nb.roundStore.Range(cleanF)
}
}
}
func (nb *Impl) Sender(sendFreq int) {
sendTicker := time.NewTicker(time.Duration(sendFreq) * time.Second)
for {
select {
case <-sendTicker.C:
notifBuf := nb.Storage.GetNotificationBuffer()
notifMap := notifBuf.Swap(maxNotifications)
notifMap := notifBuf.Swap(uint(nb.maxNotifications))
for ephID := range notifMap {
localEphID := ephID
notifList := notifMap[localEphID]
......
......@@ -94,6 +94,8 @@ func TestStartNotifications(t *testing.T) {
params := Params{
Address: "0.0.0.0:42010",
NotificationsPerBatch: 20,
NotificationRate: 30,
APNS: APNSParams{
KeyPath: "",
KeyID: "WQT68265C5",
......@@ -323,6 +325,8 @@ func TestImpl_ReceiveNotificationBatch(t *testing.T) {
func getNewImpl() *Impl {
wd, _ := os.Getwd()
params := Params{
NotificationsPerBatch: 20,
NotificationRate: 30,
Address: fmt.Sprintf("0.0.0.0:%d", port),
KeyPath: wd + "/../testutil/cmix.rip.key",
CertPath: wd + "/../testutil/cmix.rip.crt",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment