本文整理汇总了Golang中lib/server.App.Cron方法的典型用法代码示例。如果您正苦于以下问题:Golang App.Cron方法的具体用法?Golang App.Cron怎么用?Golang App.Cron使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib/server.App
的用法示例。
在下文中一共展示了App.Cron方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupCronIEPGDailyNotification
func setupCronIEPGDailyNotification(app *server.App) {
var Cron = app.Cron()
Cron.Define(
"/records/notificatoin/daily/",
"every day 08:00",
"Notification for recordings today",
func(req *wcg.Request) error {
var hasError = false
var email = configs.GetValue(req, "intern.pt.notification_email")
messengerConfigs, err := getMessengerNotificationOptInUsers(req, "Summary")
if err != nil {
return err
}
content, err := createDailyNotificationContent(req)
if err != nil {
return err
}
if email == "" {
req.Logger.Warnf(
"No notification email address is specified (SiteConfig: %q)",
"intern.pt.notification_email",
)
} else {
err := notifications.NewEmail(
email,
content.title,
strings.Join(content.lines, "\n"),
).Deliver(req)
if err != nil {
req.Logger.Errorf("Failed to deliver an email notification: %v", err)
hasError = true
} else {
req.Logger.Infof("Sent an email notification to %s", email)
}
}
if len(messengerConfigs) == 0 {
req.Logger.Infof("No messenger configuration is found. Skipped")
}
for _, cfg := range messengerConfigs {
client := messenger.NewMessengerClient(req)
client.UserID = cfg.UserID
err := client.SendText(content.title + "\n" + strings.Join(content.lines, "\n"))
if err != nil {
req.Logger.Errorf("Failed to deliver a messenger notification: %v", err)
hasError = true
} else {
req.Logger.Infof("Sent a messenger notification to %s", client.UserID)
}
}
if hasError {
return fmt.Errorf("Something wrong in daily notification cron. Check error logs.")
}
return nil
},
)
}