diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 045991de..b24edd30 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -9,33 +9,19 @@ import ( ) func main() { - file := os.Stdout - defer file.Close() if err := godotenv.Load(); err != nil { log.Info("no .env file found, using default env variables") } env := os.Getenv("APP_ENV") testing := (env == "testing") - initLogging(env, file) + initLogging() newServer := server.NewServer(testing) newServer.ListenAndServe() } -func initLogging(env string, file *os.File) { - var err error - prod := (env == "prod" || env == "production") - if prod { - file, err = os.OpenFile("logs/server.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - log.Fatalf("Failed to open log file: %v", err) - } - log.SetFormatter(&log.JSONFormatter{}) - } else { - log.SetFormatter(&log.TextFormatter{ForceColors: true}) - } - level := parseLogLevel() - log.SetLevel(level) - log.SetOutput(file) +func initLogging() { + log.SetFormatter(&log.JSONFormatter{}) + log.SetLevel(parseLogLevel()) } func parseLogLevel() log.Level { diff --git a/backend/src/handlers/helpful_links_handler.go b/backend/src/handlers/helpful_links_handler.go index dc7bdb11..dab1e21c 100644 --- a/backend/src/handlers/helpful_links_handler.go +++ b/backend/src/handlers/helpful_links_handler.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "strconv" + + "github.com/sirupsen/logrus" ) func (srv *Server) registerLeftMenuRoutes() []routeDef { @@ -160,13 +162,14 @@ func (srv *Server) handleFavoriteLink(w http.ResponseWriter, r *http.Request, lo if err != nil { return newDatabaseServiceError(err) } - if _, err := srv.Db.FavoriteOpenContent(int(userID), link.OpenContentProviderID, uint(linkID), facilityID); err != nil { + if _, err := srv.Db.FavoriteOpenContent(int(linkID), link.OpenContentProviderID, uint(userID), facilityID); err != nil { return newDatabaseServiceError(err) } return writeJsonResponse(w, http.StatusOK, "Link favorite toggled successfully") } func (srv *Server) getFavicon(link string) string { + logrus.Printf("Getting favicon for link %s", link) baseUrl, err := url.Parse(link) if err != nil { return "/ul-icon.png" diff --git a/backend/src/models/jobs.go b/backend/src/models/jobs.go index 9599ef76..1dc47bd4 100644 --- a/backend/src/models/jobs.go +++ b/backend/src/models/jobs.go @@ -74,7 +74,7 @@ const ( SyncVideoMetadataJob JobType = "sync_video_metadata" PutVideoMetadataJob JobType = "put_video_metadata" AddVideosJob JobType = "add_videos" - EveryThreeHours string = "0 */3 * * *" + EveryThreeHours string = "0 6-20 * * *" EverySundayAt8PM string = "0 20 * * 7" StatusPending JobStatus = "pending" StatusRunning JobStatus = "running" diff --git a/backend/tasks/main.go b/backend/tasks/main.go index 2da3b872..f8cdf7cf 100644 --- a/backend/tasks/main.go +++ b/backend/tasks/main.go @@ -54,31 +54,22 @@ func main() { func initLogging() { env := os.Getenv("APP_ENV") - var err error - var file *os.File if env == "development" { log.SetFormatter(&log.TextFormatter{}) - file = os.Stdout } else { log.SetFormatter(&log.JSONFormatter{}) - file, err = os.OpenFile("logs/cron.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + level, err := log.ParseLevel(os.Getenv("LOG_LEVEL")) if err != nil { - log.Error("Failed to log to file, using default stderr") - file = os.Stdout + log.Error("Failed to parse log level, using default info") + level = log.DebugLevel } + log.SetLevel(level) } - log.SetOutput(file) - level, err := log.ParseLevel(os.Getenv("LOG_LEVEL")) - if err != nil { - log.Error("Failed to parse log level, using default info") - level = log.DebugLevel - } - log.SetLevel(level) } func getCronSchedule(task *models.RunnableTask, hour int) string { if task.Provider != nil && task.Provider.Type == models.Brightspace { - return fmt.Sprintf("0 0 %d * * 4", hour) + return fmt.Sprintf("0 %d * * 4", hour) } else if task.Job.Name == string(models.PutVideoMetadataJob) { return models.EverySundayAt8PM } else { diff --git a/docker-compose.yml b/docker-compose.yml index c3963c44..1d52901e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -85,7 +85,7 @@ services: context: . dockerfile: provider-middleware/dev.Dockerfile environment: - - APP_ENV=production + - APP_ENV=dev - DB_HOST=postgres - DB_PORT=5432 - DB_USER=unlocked diff --git a/provider-middleware/kiwix.go b/provider-middleware/kiwix.go index 32deb310..b65822b4 100644 --- a/provider-middleware/kiwix.go +++ b/provider-middleware/kiwix.go @@ -7,15 +7,24 @@ import ( "fmt" "io" "net/http" + "os" + "sync" "gorm.io/gorm" ) const ( KiwixCatalogUrl = "/catalog/v2/entries?lang=eng&start=1&count=" - MaxLibraries = 1000 ) +var maxLibraries = sync.OnceValue(func() int { + if os.Getenv("APP_ENV") == "dev" { + return 10 + } else { + return 1000 + } +}) + type KiwixService struct { OpenContentProviderId uint Url string @@ -26,7 +35,7 @@ type KiwixService struct { } func NewKiwixService(openContentProvider *models.OpenContentProvider, params *map[string]interface{}) *KiwixService { - url := fmt.Sprintf("%s%s%d", openContentProvider.Url, KiwixCatalogUrl, MaxLibraries) + url := fmt.Sprintf("%s%s%d", openContentProvider.Url, KiwixCatalogUrl, maxLibraries()) client := http.Client{} jobID := (*params)["job_id"].(string) return &KiwixService{ diff --git a/provider-middleware/main.go b/provider-middleware/main.go index e94d1e4b..2f3aaa79 100644 --- a/provider-middleware/main.go +++ b/provider-middleware/main.go @@ -103,37 +103,7 @@ func main() { func initLogging() *log.Logger { var logger = log.New() - var file *os.File - var err error - env := os.Getenv("APP_ENV") - if env == "production" || env == "prod" { - file, err = os.OpenFile("logs/provider-middleware.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - file, err = os.Create("logs/provider-middleware.log") - if err != nil { - log.Fatalf("Failed to create log file: %v", err) - } - } - } else { - file = os.Stdout - } - logger.SetOutput(file) logger.SetFormatter(&log.JSONFormatter{}) - if os.Getenv("LOG_LEVEL") == "" { - switch env { - case "prod", "production": - log.SetLevel(log.InfoLevel) - case "dev", "development": - log.SetLevel(log.TraceLevel) - default: - log.SetLevel(log.DebugLevel) - } - } else { - level, err := log.ParseLevel(os.Getenv("LOG_LEVEL")) - if err != nil { - log.SetLevel(log.DebugLevel) - } - logger.SetLevel(level) - } + logger.SetLevel(log.InfoLevel) return logger }