Skip to content

Commit

Permalink
added useful debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
beebeeoii committed Jan 21, 2022
1 parent e733248 commit aa0c273
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://github.com/beebeeoii/lominus"
Name = "Lominus"
ID = "com.beebeeoii.lominus"
Version = "1.2.0"
Build = 115
Build = 116
17 changes: 16 additions & 1 deletion internal/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,29 @@ func createJob(frequency int) (*gocron.Job, error) {
LastRanChannel <- GetLastRan().Format("2 Jan 15:04:05")
}

logs.Logger.Debugln("retrieving - preferences path")
preferencesPath, getPreferencesPathErr := appPref.GetPreferencesPath()
if getPreferencesPathErr != nil {
logs.Logger.Errorln(getPreferencesPathErr)
return
}

logs.Logger.Debugln("loading - preferences")
preferences, loadPrefErr := appPref.LoadPreferences(preferencesPath)
if loadPrefErr != nil {
logs.Logger.Errorln(loadPrefErr)
return
}

logs.Logger.Debugln("building - module request")
moduleRequest, modReqErr := api.BuildModuleRequest()
if modReqErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: "Authentication failed"}
logs.Logger.Errorln(modReqErr)
return
}

logs.Logger.Debugln("retrieving - modules")
modules, modErr := moduleRequest.GetModules()
if modErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: "Unable to retrieve modules"}
Expand All @@ -124,13 +128,15 @@ func createJob(frequency int) (*gocron.Job, error) {
if preferences.Directory != "" {
updatedFiles := make([]api.File, 0)
for _, module := range modules {
logs.Logger.Debugln("building - document request")
fileRequest, fileReqErr := api.BuildDocumentRequest(module, api.GET_ALL_FILES)
if fileReqErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: "Unable to retrieve files"}
logs.Logger.Errorln(fileReqErr)
continue
}

logs.Logger.Debugln("retrieving - root files")
files, fileErr := fileRequest.GetRootFiles()
if fileErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: "Unable to retrieve files"}
Expand All @@ -154,6 +160,7 @@ func createJob(frequency int) (*gocron.Job, error) {
Entries: indexMapEntries,
})

logs.Logger.Debugln("building - index map")
currentFiles, currentFilesErr := indexing.Build(preferences.Directory)
if currentFilesErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: "Unable to sync files"}
Expand All @@ -167,6 +174,8 @@ func createJob(frequency int) (*gocron.Job, error) {
for _, file := range updatedFiles {
if _, exists := currentFiles[file.Name]; !exists || currentFiles[file.Name].LastUpdated.Before(file.LastUpdated) {
nFilesToUpdate += 1

logs.Logger.Debugf("downloading - %s into (%s)", file.Name, strings.Join(file.Ancestors, "/"))
downloadErr := downloadFile(preferences.Directory, file)
if downloadErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Sync", Content: fmt.Sprintf("Unable to download file: %s", file.Name)}
Expand Down Expand Up @@ -207,26 +216,30 @@ func createJob(frequency int) (*gocron.Job, error) {
logs.Logger.Infof("job completed: %s", time.Now().Format(time.RFC3339))
}

logs.Logger.Debugln("retrieving - telegram path")
telegramInfoPath, getTelegramInfoPathErr := intTelegram.GetTelegramInfoPath()
if getTelegramInfoPathErr != nil {
logs.Logger.Errorln(getTelegramInfoPathErr)
return
}

logs.Logger.Debugln("loading - telegram")
telegramInfo, telegramInfoErr := telegram.LoadTelegramData(telegramInfoPath)
if telegramInfoErr != nil {
logs.Logger.Errorln(telegramInfoErr)
return
}

for _, module := range modules {
logs.Logger.Debugln("building - grade request")
gradeRequest, gradeReqErr := api.BuildGradeRequest(module)
if gradeReqErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Grades", Content: "Unable to retrieve grades"}
logs.Logger.Errorln(gradeReqErr)
continue
}

logs.Logger.Debugln("retrieving - grade")
grades, gradesErr := gradeRequest.GetGrades()
if gradesErr != nil {
notifications.NotificationChannel <- notifications.Notification{Title: "Grades", Content: "Unable to retrieve grades"}
Expand All @@ -245,7 +258,9 @@ func createJob(frequency int) (*gocron.Job, error) {
continue
}

gradeMsgErr := telegram.SendMessage(telegramInfo.BotApi, telegramInfo.UserId, telegram.GenerateGradeMessageFormat(module.ModuleCode, grade.Name, grade.Comments, grade.Marks, grade.MaxMarks))
message := telegram.GenerateGradeMessageFormat(module.ModuleCode, grade.Name, grade.Comments, grade.Marks, grade.MaxMarks)
logs.Logger.Debugln("sending telegram message - %s", message)
gradeMsgErr := telegram.SendMessage(telegramInfo.BotApi, telegramInfo.UserId, message)

if gradeMsgErr != nil {
logs.Logger.Errorln(gradeMsgErr)
Expand Down

0 comments on commit aa0c273

Please sign in to comment.