Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions api/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/realtime"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -53,7 +52,7 @@ func RegisterRealtimeChatChannel() {
OnMessage: func(psc *realtime.Context, message *realtime.Message) {
foundContext, exists := psc.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
return
}
tumLiveContext := foundContext.(tools.TUMLiveContext)
Expand Down Expand Up @@ -704,23 +703,23 @@ func chatOnUnsubscribe(psc *realtime.Context) {
if ctx, ok := psc.Client.Get("dao"); ok {
daoWrapper = ctx.(dao.DaoWrapper)
} else {
sentry.CaptureException(errors.New("daoWrapper should exist but doesn't"))
logger.Error("daoWrapper should exist but doesn't")
return
}

var tumLiveContext tools.TUMLiveContext
if foundContext, exists := psc.Get("TUMLiveContext"); exists {
tumLiveContext = foundContext.(tools.TUMLiveContext)
} else {
sentry.CaptureException(errors.New("tumLiveContext should exist but doesn't"))
logger.Error("tumLiveContext should exist but doesn't")
return
}

var joinTime time.Time
if result, exists := psc.Get("chat.joinTime"); exists {
joinTime = result.(time.Time)
} else {
sentry.CaptureException(errors.New("joinTime should exist but doesn't"))
logger.Error("joinTime should exist but doesn't")
return
}

Expand Down
6 changes: 2 additions & 4 deletions api/courseimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"database/sql"
"errors"
"fmt"
"html/template"
"net/http"
Expand All @@ -14,7 +13,6 @@ import (
"unicode"

campusonline "github.com/RBG-TUM/CAMPUSOnline"
"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"

Expand All @@ -27,7 +25,7 @@ func (r lectureHallRoutes) postSchedule(c *gin.Context) {
resp := ""
foundContext, exists := c.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
Expand All @@ -42,7 +40,7 @@ func (r lectureHallRoutes) postSchedule(c *gin.Context) {
var req importReq
err := c.BindJSON(&req)
if err != nil {
sentry.CaptureException(errors.New("could not bind JSON request"))
logger.Error("could not bind JSON request", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "could not bind JSON request",
Expand Down
5 changes: 2 additions & 3 deletions api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/RBG-TUM/commons"
"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
"github.com/meilisearch/meilisearch-go"
uuid "github.com/satori/go.uuid"
Expand Down Expand Up @@ -368,7 +367,7 @@ func (r coursesRoutes) getCourseBySlug(c *gin.Context) {
CustomMessage: "can't find course",
})
} else {
sentry.CaptureException(err)
logger.Error("can't retrieve course", "err", err)
_ = c.Error(tools.RequestError{
Err: err,
Status: http.StatusInternalServerError,
Expand Down Expand Up @@ -786,7 +785,7 @@ type lhResp struct {
func (r coursesRoutes) lectureHallsByID(c *gin.Context) {
foundContext, exists := c.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
Expand Down
4 changes: 1 addition & 3 deletions api/download.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package api

import (
"errors"
"fmt"
"net/http"
"os"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"

"github.com/TUM-Dev/gocast/dao"
Expand All @@ -31,7 +29,7 @@ var dlErr = tools.RequestError{
func (r downloadRoutes) download(c *gin.Context) {
foundContext, exists := c.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
Expand Down
4 changes: 1 addition & 3 deletions api/lecture_halls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package api

import (
"embed"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"text/template"
"time"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"

"github.com/TUM-Dev/gocast/dao"
Expand Down Expand Up @@ -227,7 +225,7 @@ func (r lectureHallRoutes) lectureHallIcal(c *gin.Context) {
}
foundContext, exists := c.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
Expand Down
6 changes: 2 additions & 4 deletions api/live_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package api

import (
"encoding/json"
"errors"
"sync"

"github.com/RBG-TUM/commons"
"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"

"github.com/TUM-Dev/gocast/dao"
Expand Down Expand Up @@ -42,7 +40,7 @@ func liveUpdateOnUnsubscribe(psc *realtime.Context) {
ctx, _ := psc.Client.Get("ctx") // get gin context
foundContext, exists := ctx.(*gin.Context).Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
return
}

Expand Down Expand Up @@ -74,7 +72,7 @@ func liveUpdateOnSubscribe(psc *realtime.Context) {

foundContext, exists := ctx.(*gin.Context).Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
return
}

Expand Down
18 changes: 8 additions & 10 deletions api/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/TUM-Dev/gocast/tools/pathprovider"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm"
Expand Down Expand Up @@ -102,16 +101,15 @@ type liveStreamDto struct {

func (r streamRoutes) getThumbs(c *gin.Context) {
ctx, exists := c.Get("TUMLiveContext")
tumLiveContext := ctx.(tools.TUMLiveContext)

if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
})
return
}
tumLiveContext := ctx.(tools.TUMLiveContext)
file, err := r.GetFileById(c.Param("fid"))
if err != nil {
_ = c.Error(tools.RequestError{
Expand Down Expand Up @@ -270,7 +268,7 @@ func (r streamRoutes) reportStreamIssue(c *gin.Context) {

var alert alertMessage
if err := c.ShouldBindJSON(&alert); err != nil {
sentry.CaptureException(err)
logger.Error("can not bind body", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusBadRequest,
CustomMessage: "can not bind body",
Expand All @@ -281,7 +279,7 @@ func (r streamRoutes) reportStreamIssue(c *gin.Context) {
// Get lecture hall of the stream that has issues.
lectureHall, err := r.LectureHallsDao.GetLectureHallByID(stream.LectureHallID)
if err != nil {
sentry.CaptureException(err)
logger.Error("can not get lecturehall by id", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "can not get lecturehall by id",
Expand All @@ -293,7 +291,7 @@ func (r streamRoutes) reportStreamIssue(c *gin.Context) {
// Get course of the stream that has issues.
course, err := r.CoursesDao.GetCourseById(c, stream.CourseID)
if err != nil {
sentry.CaptureException(err)
logger.Error("can not get course by id", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "can not get course by id",
Expand Down Expand Up @@ -331,7 +329,7 @@ func (r streamRoutes) reportStreamIssue(c *gin.Context) {

// Set messaging strategy as specified in strategy pattern
if err = alertBot.SendAlert(botInfo, r.StatisticsDao); err != nil {
sentry.CaptureException(err)
logger.Error("can not send bot alert", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "can not send bot alert",
Expand Down Expand Up @@ -772,7 +770,7 @@ func (r streamRoutes) requestSubtitles(c *gin.Context) {
var request subtitleRequest
err := c.BindJSON(&request)
if err != nil {
sentry.CaptureException(err)
logger.Error("can not bind body", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusBadRequest,
CustomMessage: "can not bind body",
Expand Down Expand Up @@ -810,7 +808,7 @@ func (r streamRoutes) requestSubtitles(c *gin.Context) {
// request to voice-service for subtitles
client, err := GetSubtitleGeneratorClient()
if err != nil {
sentry.CaptureException(err)
logger.Error("could not connect to voice-service", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "could not connect to voice-service",
Expand Down
8 changes: 3 additions & 5 deletions api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
"time"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
"gorm.io/gorm"

Expand Down Expand Up @@ -263,8 +262,7 @@ func (r usersRoutes) DeleteUser(c *gin.Context) {

err = r.UsersDao.DeleteUser(context.Background(), deleteRequest.Id)
if err != nil {
sentry.CaptureException(err)
defer sentry.Flush(time.Second * 2)
logger.Error("can not delete user", "err", err)
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "can not delete user",
Expand All @@ -278,7 +276,7 @@ func (r usersRoutes) DeleteUser(c *gin.Context) {
func (r usersRoutes) CreateUserForCourse(c *gin.Context) {
foundContext, exists := c.Get("TUMLiveContext")
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
_ = c.Error(tools.RequestError{
Status: http.StatusInternalServerError,
CustomMessage: "context should exist but doesn't",
Expand Down Expand Up @@ -379,7 +377,7 @@ func (r usersRoutes) getPinForCourse(c *gin.Context) {
if tumLiveContext.User != nil {
has, err = r.UsersDao.HasPinnedCourse(*tumLiveContext.User, uri.CourseId)
if err != nil {
sentry.CaptureException(err)
logger.Error("can't retrieve course", "err", err)
_ = c.Error(tools.RequestError{
Err: err,
Status: http.StatusInternalServerError,
Expand Down
5 changes: 0 additions & 5 deletions api/worker_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

go_anel_pwrctrl "github.com/RBG-TUM/go-anel-pwrctrl"
"github.com/getsentry/sentry-go"
uuid "github.com/satori/go.uuid"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -731,19 +730,16 @@ func NotifyWorkers(daoWrapper dao.DaoWrapper) func() {
err := daoWrapper.StreamsDao.SaveEndedState(streams[i].ID, false)
if err != nil {
logger.Warn("Can't set stream undone", "err", err)
sentry.CaptureException(err)
continue
}
courseForStream, err := daoWrapper.CoursesDao.GetCourseById(context.Background(), streams[i].CourseID)
if err != nil {
logger.Warn("Can't get course for stream, skipping", "err", err)
sentry.CaptureException(err)
continue
}
lectureHallForStream, err := daoWrapper.LectureHallsDao.GetLectureHallByID(streams[i].LectureHallID)
if err != nil {
logger.Error("Can't get lecture hall for stream, skipping", "err", err)
sentry.CaptureException(err)
continue
}

Expand Down Expand Up @@ -779,7 +775,6 @@ func notifyWorkersPremieres(daoWrapper dao.DaoWrapper) {
err := daoWrapper.StreamsDao.SaveEndedState(streams[i].ID, false)
if err != nil {
logger.Warn("Can't set stream undone", "err", err)
sentry.CaptureException(err)
continue
}
if len(streams[i].Files) == 0 {
Expand Down
4 changes: 1 addition & 3 deletions api/wsHub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package api
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"sync"
"time"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"

"github.com/TUM-Dev/gocast/dao"
Expand All @@ -36,7 +34,7 @@ type sessionWrapper struct {
var connHandler = func(context *realtime.Context) {
foundContext, exists := context.Get("TUMLiveContext") // get gin context
if !exists {
sentry.CaptureException(errors.New("context should exist but doesn't"))
logger.Error("context should exist but doesn't")
return
}
tumLiveContext := foundContext.(tools.TUMLiveContext)
Expand Down
3 changes: 0 additions & 3 deletions cmd/tumlive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/dgraph-io/ristretto/v2"
"github.com/getsentry/sentry-go"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
slogGorm "github.com/orandin/slog-gorm"
Expand Down Expand Up @@ -270,8 +269,6 @@ func initCron(logger *slog.Logger, m *runner_manager.Manager) {
_ = tools.Cron.AddFunc("fetchCourses", tum.FetchCourses(daoWrapper), "0 */12 * * *")
// Collect livestream stats (viewers) every minute
_ = tools.Cron.AddFunc("collectStats", api.CollectStats(daoWrapper), "0-59 * * * *")
// Flush stale sentry exceptions and transactions every 5 minutes
_ = tools.Cron.AddFunc("sentryFlush", func() { sentry.Flush(time.Minute * 2) }, "0-59/5 * * * *")
// Look for due streams and notify workers about them
_ = tools.Cron.AddFunc("triggerDueStreams", api.NotifyWorkers(daoWrapper), "0-59 * * * *")
_ = tools.Cron.AddFunc("triggerDueStreamsRunner", func() {
Expand Down
3 changes: 0 additions & 3 deletions dao/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/TUM-Dev/gocast/model"

"github.com/RBG-TUM/commons"
"github.com/getsentry/sentry-go"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -148,8 +147,6 @@ func (d CoursesDaoImpl) GetAdministeredCoursesByUserId(ctx context.Context, user
}

func (d CoursesDaoImpl) GetAllCoursesForSemester(ctx context.Context, year int, term string) (courses []model.Course) {
span := sentry.StartSpan(ctx, "SQL: GetAllCoursesForSemester")
defer span.Finish()
var foundCourses []model.Course
DB.Preload("Streams", func(db *gorm.DB) *gorm.DB {
return db.Order("start asc")
Expand Down
Loading
Loading