本文整理匯總了Golang中github.com/rafaeljusto/shelter/dao.DomainDAO.FindAllAsyncToBeNotified方法的典型用法代碼示例。如果您正苦於以下問題:Golang DomainDAO.FindAllAsyncToBeNotified方法的具體用法?Golang DomainDAO.FindAllAsyncToBeNotified怎麽用?Golang DomainDAO.FindAllAsyncToBeNotified使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rafaeljusto/shelter/dao.DomainDAO
的用法示例。
在下文中一共展示了DomainDAO.FindAllAsyncToBeNotified方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: domainsNotification
//.........這裏部分代碼省略.........
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
for i := item.numberOfItems / 5 * 2; i < item.numberOfItems/5*3; i++ {
domain := model.Domain{
FQDN: fmt.Sprintf("%s%d.com.br", item.name, i),
DSSet: []model.DS{
{
LastStatus: model.DSStatusTimeout,
LastOKAt: item.dsTimeoutLastOkAt,
ExpiresAt: time.Now().Add(time.Duration((maxExpirationAlertDays+1)*24) * time.Hour),
},
},
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
for i := item.numberOfItems / 5 * 3; i < item.numberOfItems/5*4; i++ {
domain := model.Domain{
FQDN: fmt.Sprintf("%s%d.com.br", item.name, i),
DSSet: []model.DS{
{
LastStatus: model.DSStatusExpiredSignature,
LastOKAt: item.dsErrorLastOkAt,
ExpiresAt: time.Now().Add(time.Duration((maxExpirationAlertDays+1)*24) * time.Hour),
},
},
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
for i := item.numberOfItems / 5 * 4; i < item.numberOfItems; i++ {
domain := model.Domain{
FQDN: fmt.Sprintf("%s%d.com.br", item.name, i),
DSSet: []model.DS{
{
LastStatus: model.DSStatusOK,
LastOKAt: time.Now(),
ExpiresAt: item.dsExpiresAt,
},
},
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
}
domainChannel, err := domainDAO.FindAllAsyncToBeNotified(
nameserverErrorAlertDays,
nameserverTimeoutAlertDays,
dsErrorAlertDays,
dsTimeoutAlertDays,
maxExpirationAlertDays,
)
if err != nil {
utils.Fatalln("Error retrieving domains to be notified", err)
}
var domains []*model.Domain
for {
domainResult := <-domainChannel
if domainResult.Error != nil {
utils.Fatalln("Error retrieving domain to be notified", domainResult.Error)
}
if domainResult.Error != nil || domainResult.Domain == nil {
break
}
domains = append(domains, domainResult.Domain)
}
if len(domains) != numberOfItemsToBeVerified {
utils.Fatalln(fmt.Sprintf("Did not select all the domains ready for notification. "+
"Expected %d and got %d", numberOfItemsToBeVerified, len(domains)), nil)
}
for _, item := range data {
for i := 0; i < item.numberOfItems; i++ {
fqdn := fmt.Sprintf("%s%d.com.br", item.name, i)
if err := domainDAO.RemoveByFQDN(fqdn); err != nil {
utils.Fatalln("Error removing domain from database", err)
}
}
}
}
示例2: Notify
// Notify is responsable for selecting the domains that should be notified in the system.
// It will send alert e-mails for each owner of a domain
func Notify() {
defer func() {
// Something went really wrong while notifying the owners. Log the error stacktrace
// and move out
if r := recover(); r != nil {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Printf("Panic detected while notifying the owners. Details: %v\n%s", r, buf)
}
}()
log.Info("Start notification job")
defer func() {
log.Info("End notification job")
}()
log.Debugf("Initializing database with the parameters: URIS - %v | Name - %s | Auth - %t | Username - %s",
config.ShelterConfig.Database.URIs,
config.ShelterConfig.Database.Name,
config.ShelterConfig.Database.Auth.Enabled,
config.ShelterConfig.Database.Auth.Username,
)
database, databaseSession, err := mongodb.Open(
config.ShelterConfig.Database.URIs,
config.ShelterConfig.Database.Name,
config.ShelterConfig.Database.Auth.Enabled,
config.ShelterConfig.Database.Auth.Username,
config.ShelterConfig.Database.Auth.Password,
)
if err != nil {
log.Println("Error while initializing database. Details:", err)
return
}
defer databaseSession.Close()
domainDAO := dao.DomainDAO{
Database: database,
}
domainChannel, err := domainDAO.FindAllAsyncToBeNotified(
config.ShelterConfig.Notification.NameserverErrorAlertDays,
config.ShelterConfig.Notification.NameserverTimeoutAlertDays,
config.ShelterConfig.Notification.DSErrorAlertDays,
config.ShelterConfig.Notification.DSTimeoutAlertDays,
// TODO: Should we move this configuration parameter to a place were both modules can
// access it. This sounds better for configuration deployment
config.ShelterConfig.Scan.VerificationIntervals.MaxExpirationAlertDays,
)
if err != nil {
log.Println("Error retrieving domains to notify. Details:", err)
return
}
// Dispatch the asynchronous part of the method
for {
// Get domain from the database (one-by-one)
domainResult := <-domainChannel
// Detect errors while retrieving a specific domain. We are not going to stop all the
// process when only one domain got an error
if domainResult.Error != nil {
log.Println("Error retrieving domain to notify. Details:", domainResult.Error)
continue
}
// Problem detected while retrieving a domain or we don't have domains anymore
if domainResult.Error != nil || domainResult.Domain == nil {
break
}
if err := notifyDomain(domainResult.Domain); err != nil {
log.Println("Error notifying a domain. Details:", err)
}
}
}