Example #1
0
func SetupSocketIO() (*socketio.Server, error) {
	server, err := socketio.NewServer(nil)
	if err != nil {
		return nil, err
	}

	server.On("connection", func(so socketio.Socket) {
		logging.InfoWithTags([]string{"socket.io"}, "New socket.io connection:", so.Id())
		//so.Join("feedbag")
		so.On("disconnection", func() {
			// no op
		})
	})
	server.On("error", func(so socketio.Socket, err error) {
		logging.ErrorWithTags([]string{"socket.io"}, "Error on socket.io server", err.Error())
	})

	server.On("checkout", func(msg string) {
		logging.InfoWithTags([]string{"socket.io"}, "New socket.io connection ups i did it again:", msg)
		log.Println("emit:", msg)
	})

	return server, nil
}
Example #2
0
func ActivityParser(p ActivityPayloadList) []Activity {
	activities := ActivityList{}

	for _, payload := range p {
		isBreak := make(map[string]bool)

		// Sort templates by priority
		sort.Sort(ByPriority{Templates})

		for _, template := range Templates {
			activity := Activity{}

			//Set the event time on the activity object to the payloads event time
			activity.EventTime = payload.EventTime

			if isBreak[template.Event] {
				continue
			}

			if CheckEventType(template.Event, payload) && ValidateConditional(template.Condition, payload) {
				if template.Break {
					isBreak[template.Event] = true
				}

				logging.InfoWithTags([]string{"activity"}, "Adding activity for event ", activity.Event.EventType)

				//Create the activity for this template and append to list
				activity.TemplateId = template.Id
				activity.Event = payload
				activity.UpdateTime()

				err := activity.Create()
				if err != nil {
					logging.WarnWithTags([]string{"activity"}, "Failed to save activity", err.Error())
				}

				activities = append(activities, activity)

			}
		}
	}

	return activities
}