@@ -18,5 +18,6 @@ var (
|
||||
// LogAccess is log server request log
|
||||
LogAccess *logrus.Logger
|
||||
// LogError is log server error log
|
||||
LogError *logrus.Logger
|
||||
LogError *logrus.Logger
|
||||
RushStatus StatusApp
|
||||
)
|
||||
|
||||
@@ -158,9 +158,11 @@ func queueNotification(req RequestPush) int {
|
||||
}
|
||||
QueueNotification <- notification
|
||||
|
||||
count++
|
||||
count += len(notification.Tokens)
|
||||
}
|
||||
|
||||
addTotalCount(int64(count))
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -276,6 +278,7 @@ func PushToIOS(req PushNotification) bool {
|
||||
// apns server error
|
||||
LogPush(FailedPush, token, req, err)
|
||||
isError = true
|
||||
addIosError(1)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -283,11 +286,13 @@ func PushToIOS(req PushNotification) bool {
|
||||
// error message:
|
||||
// ref: https://github.com/sideshow/apns2/blob/master/response.go#L14-L65
|
||||
LogPush(FailedPush, token, req, errors.New(res.Reason))
|
||||
addIosError(1)
|
||||
continue
|
||||
}
|
||||
|
||||
if res.Sent() {
|
||||
LogPush(SucceededPush, token, req, nil)
|
||||
addIosSuccess(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,6 +385,8 @@ func PushToAndroid(req PushNotification) bool {
|
||||
}
|
||||
|
||||
LogAccess.Debug(fmt.Sprintf("Android Success count: %d, Failure count: %d", res.Success, res.Failure))
|
||||
addAndroidSuccess(int64(res.Success))
|
||||
addAndroidError(int64(res.Failure))
|
||||
|
||||
for k, result := range res.Results {
|
||||
if result.Error != "" {
|
||||
|
||||
@@ -355,7 +355,7 @@ func TestSenMultipleNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
count := queueNotification(req)
|
||||
assert.Equal(t, 2, count)
|
||||
assert.Equal(t, 3, count)
|
||||
}
|
||||
|
||||
func TestDisabledAndroidNotifications(t *testing.T) {
|
||||
@@ -421,7 +421,7 @@ func TestDisabledIosNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
count := queueNotification(req)
|
||||
assert.Equal(t, 1, count)
|
||||
assert.Equal(t, 2, count)
|
||||
}
|
||||
|
||||
func TestMissingIosCertificate(t *testing.T) {
|
||||
|
||||
51
gorush/status.go
Normal file
51
gorush/status.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package gorush
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type StatusApp struct {
|
||||
QueueMax int `json:"queue_max"`
|
||||
QueueUsage int `json:"queue_usage"`
|
||||
TotalCount int64 `json:"total_count"`
|
||||
Ios IosStatus `json:"ios"`
|
||||
Android AndroidStatus `json:"android"`
|
||||
}
|
||||
|
||||
type AndroidStatus struct {
|
||||
PushSuccess int64 `json:"push_success"`
|
||||
PushError int64 `json:"push_error"`
|
||||
}
|
||||
|
||||
type IosStatus struct {
|
||||
PushSuccess int64 `json:"push_success"`
|
||||
PushError int64 `json:"push_error"`
|
||||
}
|
||||
|
||||
func InitAppStatus() {
|
||||
RushStatus.TotalCount = 0
|
||||
RushStatus.Ios.PushSuccess = 0
|
||||
RushStatus.Ios.PushError = 0
|
||||
RushStatus.Android.PushSuccess = 0
|
||||
RushStatus.Android.PushError = 0
|
||||
}
|
||||
|
||||
func addTotalCount(count int64) {
|
||||
atomic.AddInt64(&RushStatus.TotalCount, count)
|
||||
}
|
||||
|
||||
func addIosSuccess(count int64) {
|
||||
atomic.AddInt64(&RushStatus.Ios.PushSuccess, count)
|
||||
}
|
||||
|
||||
func addIosError(count int64) {
|
||||
atomic.AddInt64(&RushStatus.Ios.PushError, count)
|
||||
}
|
||||
|
||||
func addAndroidSuccess(count int64) {
|
||||
atomic.AddInt64(&RushStatus.Android.PushSuccess, count)
|
||||
}
|
||||
|
||||
func addAndroidError(count int64) {
|
||||
atomic.AddInt64(&RushStatus.Android.PushError, count)
|
||||
}
|
||||
52
gorush/status_test.go
Normal file
52
gorush/status_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package gorush
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddTotalCount(t *testing.T) {
|
||||
InitAppStatus()
|
||||
addTotalCount(1000)
|
||||
|
||||
val := atomic.LoadInt64(&RushStatus.TotalCount)
|
||||
|
||||
assert.Equal(t, int64(1000), val)
|
||||
}
|
||||
|
||||
func TestAddIosSuccess(t *testing.T) {
|
||||
InitAppStatus()
|
||||
addIosSuccess(1000)
|
||||
|
||||
val := atomic.LoadInt64(&RushStatus.Ios.PushSuccess)
|
||||
|
||||
assert.Equal(t, int64(1000), val)
|
||||
}
|
||||
|
||||
func TestAddIosError(t *testing.T) {
|
||||
InitAppStatus()
|
||||
addIosError(1000)
|
||||
|
||||
val := atomic.LoadInt64(&RushStatus.Ios.PushError)
|
||||
|
||||
assert.Equal(t, int64(1000), val)
|
||||
}
|
||||
|
||||
func TestAndroidSuccess(t *testing.T) {
|
||||
InitAppStatus()
|
||||
addAndroidSuccess(1000)
|
||||
|
||||
val := atomic.LoadInt64(&RushStatus.Android.PushSuccess)
|
||||
|
||||
assert.Equal(t, int64(1000), val)
|
||||
}
|
||||
|
||||
func TestAddAndroidError(t *testing.T) {
|
||||
InitAppStatus()
|
||||
addAndroidError(1000)
|
||||
|
||||
val := atomic.LoadInt64(&RushStatus.Android.PushError)
|
||||
|
||||
assert.Equal(t, int64(1000), val)
|
||||
}
|
||||
Reference in New Issue
Block a user