Skip to content

Commit

Permalink
Add more logging to email receive job
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed May 10, 2022
1 parent 71f1906 commit cff07e1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/inbox/receive-emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (j *ReceiveEmailsJob) Execute() {
Folder: os.Getenv("OPERATOR_INBOX"),
}

log.Println("Fetching unread operator emails")
emails, err := eazye.GetUnread(auth, true, false)
if err != nil {
log.Printf("Failed to get incoming emails: %v\n", err)
Expand All @@ -50,6 +51,7 @@ func (j *ReceiveEmailsJob) Execute() {
continue
}

log.Println("Found new subscription email, adding to list")
newReaders = append(newReaders, r)
} else if strings.HasPrefix(subjectCleaned, "[op] update") {
r, err := ParseBody(email, *j.Policy)
Expand All @@ -58,13 +60,16 @@ func (j *ReceiveEmailsJob) Execute() {
continue
}

log.Println("Found new information update email, adding to list")
updatedReaders = append(updatedReaders, r)
} else if strings.HasPrefix(subjectCleaned, "[op] unsubscribe") {
log.Println("Found new unsubscribe email, adding to list")
unsubscribers = append(unsubscribers, email.From.Address)
}
}

if len(newReaders) == 0 && len(updatedReaders) == 0 && len(unsubscribers) == 0 {
log.Println("No unread operator emails found")
return
}

Expand All @@ -77,16 +82,19 @@ func (j *ReceiveEmailsJob) Execute() {

// Save new readers to the database
if len(newReaders) > 0 {
log.Println("Processing new subscribers")
saveSubscribers(readerConn, newReaders)
}

// Persist reader updates to the database
if len(updatedReaders) > 0 {
log.Println("Processing information update requests")
saveUpdatedInfo(readerConn, updatedReaders)
}

// Delete unsubscribing readers from the database
if len(unsubscribers) > 0 {
log.Println("Processing unsubscribers")
deleteUnsubscribers(readerConn, unsubscribers)
}
}
Expand Down

0 comments on commit cff07e1

Please sign in to comment.