Commit 9ee8e3a7 authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

periodic notification fixes

parent 8d912380
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -444,7 +444,7 @@ repo:
        # enable meepctl deploy/delete
        deploy: true
        # supports code coverage measurement when built in codecov mode
        codecov: false
        codecov: true
        # supports linting
        lint: true
        # location of API specifications
@@ -1023,6 +1023,11 @@ repo:
        src: go-packages/meep-sessions
        # supports linting
        lint: true
      meep-subscriptions:
        # location of source code
        src: go-packages/meep-subscriptions
        # supports linting
        lint: true
      meep-users:
        # location of source code
        src: go-packages/meep-users
+10 −6
Original line number Diff line number Diff line
@@ -272,12 +272,12 @@ func (sm *SubscriptionMgr) ReadyToSend(sub *Subscription) bool {
	if sub == nil {
		return false
	}

	sm.mutex.Lock()
	defer sm.mutex.Unlock()

	// Subscription state
	if sub.State != StateReady {
		return false
	}
	// Websocket state
	if sub.Ws != nil && sub.Ws.State != WsStateReady {
	if !sub.isReady() {
		return false
	}
	// Periodic interval
@@ -453,13 +453,17 @@ func (sm *SubscriptionMgr) runTicker() {
				if sub.PeriodicCounter > 0 {
					sub.PeriodicCounter--
				}
				if sub.PeriodicCounter == 0 && sub.State == StateReady {
				// If periodic interval is up, trigger notification if subscription is ready
				if sub.PeriodicCounter == 0 && sub.isReady() {
					// Set counter to -1; it will be reset when notification is sent
					sub.PeriodicCounter = periodicCounterPending

					// Invoke periodic callback
					log.Debug("Invoking periodic callback for sub: ", sub.Cfg.Id)
					go sm.cfg.PeriodicSubCb(sub)
				} else if sub.PeriodicCounter == periodicCounterPending && sub.isReady() {
					// Handle error cases where notification was not sent
					sub.PeriodicCounter = sub.Cfg.PeriodicInterval
				}
			}
		}
+12 −0
Original line number Diff line number Diff line
@@ -275,3 +275,15 @@ func (sub *Subscription) sendWsRequest(request *http.Request) (*http.Response, e

	return resp, nil
}

func (sub *Subscription) isReady() bool {
	// Subscription state
	if sub.State != StateReady {
		return false
	}
	// Websocket state
	if sub.Ws != nil && sub.Ws.State != WsStateReady {
		return false
	}
	return true
}
+2 −2
Original line number Diff line number Diff line
@@ -130,8 +130,8 @@ func (ws *Websocket) startMsgHandler() {
		if err != nil {
			log.Error(err.Error())

			// Reset websocket state
			ws.State = WsStateInit
			// Close websocket
			ws.close()
			return
		}