Example #1
0
func Start() {
	for {
		time.Sleep(time.Second * interval)
		redis := database.GetRedisConnection()
		logger.Log("Attempting Cron")
		ok, _ := redis.SetNX("run_cron", "true", interval*time.Second).Result()
		if ok != false {
			logger.Log("Cron Started")
			runCron()
		} else {
			logger.Log("Ignoring Cron")
		}
	}
}
Example #2
0
func RecordsBulkQueryHandler(c echo.Context) error {
	s := session.NewSession(c)

	if !s.AuthFailed {

		request := s.GetParam("request").(map[string]interface{})
		requests := request["requests"].([]interface{})

		c := make(chan bool, len(requests))

		for _, request := range requests {
			go func(request interface{}, session *session.Session) {
				endpoint := session.GetApplication().FindEndpointByName(request.(map[string]interface{})["endpoint"].(string))
				guid := request.(map[string]interface{})["guid"].(string)

				t := time.Now()

				if plugin.CheckPlugin("query", endpoint) {
					s := session.CopySessionForBulkRequest(guid)
					plugin.RunPlugin("query", endpoint, s)
					session.CopyResponseFromSessionForBulkRequest(s, guid, endpoint.Name)
				} else {
					r := request.(map[string]interface{})["request"].(map[string]interface{})
					records, count := endpoint.FindReadRecordsWhere(r["where"].(map[string]interface{}), session.User)
					session.SetRecordsAndCalculateCapabilitiesForUserForGuid(endpoint.Name, records, session.User, guid)
					session.SetRecordCountForGuid(count, guid)
				}

				logger.Log("Bulk Loaded:", "/"+endpoint.ApplicationId.Hex()+"/"+endpoint.Name+"/query", time.Now().Sub(t).String(), session.User.Id.Hex())
				c <- true
			}(request, &s)
		}

		i := 0

		for {
			<-c
			i++
			if i >= len(requests) {
				break
			}
		}
	}

	s.Write()

	return nil
}