diff --git a/downloader/discordNotifier.go b/downloader/discordNotifier.go index fa18ab7..6e77519 100644 --- a/downloader/discordNotifier.go +++ b/downloader/discordNotifier.go @@ -10,6 +10,13 @@ import ( "os" ) +func NotifyDiscordErrorless(message string) { + err := NotifyDiscord(message) + if err != nil { + log.Printf("Error notifying discord: %v", err) + } +} + func NotifyDiscord(message string) error { webhookURL := os.Getenv("YTDL_DISCORD_WEBHOOK_URL") if webhookURL == "" { diff --git a/downloader/main.go b/downloader/main.go index dd1e4b2..b95c55c 100644 --- a/downloader/main.go +++ b/downloader/main.go @@ -44,21 +44,13 @@ type DLHandler struct{} func (*DLHandler) HandleMessage(message *nsq.Message) error { log.Printf("Received message '%s' with %d attempts", message.Body, message.Attempts) - err := NotifyDiscord(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts)) - if err != nil { - Error.Printf("Error notifying discord: %v", err) - return err - } + NotifyDiscordErrorless(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts)) data := DownloadRequest{} - err = json.Unmarshal(message.Body, &data) + err := json.Unmarshal(message.Body, &data) if err != nil { Error.Printf("Error unmarshalling message: %v", err) - err = NotifyDiscord(fmt.Sprintf("Error unmarshalling message: %v", err)) - if err != nil { - Error.Printf("Error notifying discord: %v", err) - return err - } + NotifyDiscordErrorless(fmt.Sprintf("Error unmarshalling message: %v", err)) return err } @@ -82,19 +74,11 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error { err = downloader.Download(data.Link) if err != nil { Error.Printf("Error downloading %s: %v", data.Link, err) - err = NotifyDiscord(fmt.Sprintf("Error downloading %s: %v", data.Link, err)) - if err != nil { - Error.Printf("Error notifying discord: %v", err) - return err - } + NotifyDiscordErrorless(fmt.Sprintf("Error downloading %s: %v", data.Link, err)) return err } message.Finish() - err = NotifyDiscord(fmt.Sprintf("Downloaded %s", data.Link)) - if err != nil { - Error.Printf("Error notifying discord: %v", err) - return err - } + NotifyDiscordErrorless(fmt.Sprintf("Downloaded %s", data.Link)) return nil }