Skip to content

Commit

Permalink
Merge branch 'main' into feature/kino-api
Browse files Browse the repository at this point in the history
# Conflicts:
#	client/go.mod
#	client/go.sum
  • Loading branch information
CommanderStorm committed Sep 21, 2023
2 parents c420900 + 301a0c7 commit c04c21a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
15 changes: 7 additions & 8 deletions server/backend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ import (

// deviceBuffer stores all recent device calls in a buffer and flushes them to the database periodically
type deviceBuffer struct {
lock sync.Mutex
devices map[string]*model.Devices // key is uuid
interval time.Duration // flush interval
lock sync.Mutex
devices map[string]*model.Devices // key is uuid
}

func newDeviceBuffer() *deviceBuffer {
return &deviceBuffer{
lock: sync.Mutex{},
devices: make(map[string]*model.Devices),
interval: time.Minute,
lock: sync.Mutex{},
devices: make(map[string]*model.Devices),
}

}

const FlushingInterval = time.Minute

func (s *CampusServer) RunDeviceFlusher() error {
for {
time.Sleep(s.deviceBuf.interval)
time.Sleep(FlushingInterval)
if err := s.deviceBuf.flush(s.db); err != nil {
log.WithError(err).Error("Error flushing device buffer")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewCronRepository(db *gorm.DB) (*Repository, error) {

token, err := ios_apns_jwt.NewToken()
if err != nil {
log.WithError(err).Fatal("Could not create APNs token")
log.WithError(err).Error("Could not create APNs token")
}

return NewRepository(db, token), nil
Expand Down
2 changes: 1 addition & 1 deletion server/backend/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewIOSNotificationsService() *IOSNotificationsService {

token, err := ios_apns_jwt.NewToken()
if err != nil {
log.WithError(err).Fatal("failed to create new token")
log.WithError(err).Error("failed to create new token")
}

return &IOSNotificationsService{
Expand Down
15 changes: 6 additions & 9 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
grpc.WithUnaryInterceptor(addMethodNameInterceptor),
}
if err := pb.RegisterCampusHandlerFromEndpoint(context.Background(), grpcGatewayMux, httpPort, opts); err != nil {
log.WithError(err).Panic("could not RegisterCampusHandlerFromEndpoint")
log.WithError(err).Fatal("could not RegisterCampusHandlerFromEndpoint")
}
httpMux.Handle("/v1/", http.StripPrefix("/v1", grpcGatewayMux))

Expand All @@ -128,18 +128,15 @@ func main() {

// setupDB connects to the database and migrates it if necessary
func setupDB() *gorm.DB {
// Connect to DB
var conn gorm.Dialector
if dbHost := os.Getenv("DB_DSN"); dbHost == "" {
dbHost := os.Getenv("DB_DSN")
if dbHost == "" {
log.Fatal("Failed to start! The 'DB_DSN' environment variable is not defined. Take a look at the README.md for more details.")
} else {
log.Info("Connecting to dsn")
conn = mysql.Open(dbHost)
}

db, err := gorm.Open(conn, &gorm.Config{Logger: gorm_logrus.New()})
log.Info("Connecting to dsn")
db, err := gorm.Open(mysql.Open(dbHost), &gorm.Config{Logger: gorm_logrus.New()})
if err != nil {
log.WithError(err).Panic("failed to connect database")
log.WithError(err).Fatal("failed to connect database")
}

// Migrate the schema
Expand Down

0 comments on commit c04c21a

Please sign in to comment.