// SendTestEmail checks the email configuration by attempting to send out a test email func SendTestEmail() error { err := email.SendEmail(conf.Email, "This is a test email from gobl. Let me be the first to congratulate you on receiving this message: it means your email is configured correctly. Way to go!", "Netfung Gobl Coordinator") if err != nil { log.Errorf("manager", "could not sent test email: %v", err.Error()) return err } return nil }
// FinishJob updates the job status in the DB and begins the file indexing process func FinishJob(id int) error { job, err := gDb.GetJob(id) if err != nil { return err } count, err := gDb.JobErrorCount(id) if err != nil { return err } if count > 0 { job.State = spec.Errors m := "Job finished with " + strconv.Itoa(count) + " error(s)" job.Message = &m } else { job.State = spec.Complete } t := time.Now() job.End = &t err = gDb.UpdateJob(job) if err != nil { return err } // Todo: index table for files lookup if conf.Email.Configured() { a, _ := gDb.GetAgent(job.AgentID) var msg string if job.Message != nil { msg = *job.Message } else { msg = "" } body := "Job Complete: " + strconv.Itoa(job.ID) + "\n" body += "Agent: " + a.Name + "\n" body += "Start: " + job.Start.String() + "\nEnd: " + job.End.String() + "\nDuration: " + fmt.Sprintf("%v", job.End.Sub(*job.Start)) + "\n" body += "Message: " + msg + "\n\n" body += "Job Definition: " + fmt.Sprintf("%+v", job.Definition) email.SendEmail(conf.Email, body, "Job Report: "+strconv.Itoa(job.ID)) } return nil }