コード例 #1
0
ファイル: schedules.go プロジェクト: sethjback/gobl
func (s *ScheduledJob) Run() {
	jobID, err := RunBackup(s.Schedule.Backup)
	if err != nil {
		log.Errorf("scheduler", "Could not run scheduled Backup: %v. Error: ", *s, err)
	}
	log.Infof("scheduler", "Scheduled Job started. ID: %v", jobID)
}
コード例 #2
0
ファイル: main.go プロジェクト: sethjback/gobl
// 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
}
コード例 #3
0
ファイル: main.go プロジェクト: sethjback/gobl
func initCron() error {
	schedules = cron.New()
	ss, err := gDb.ScheduleList()
	if err != nil {
		log.Errorf("manager", "Could not init schedule list: %v", err)
		return err
	}

	for _, s := range ss {

		schedules.AddJob(s.String(), &ScheduledJob{s})
	}

	schedules.Start()

	log.Infof("scheduler", "Active Schedules: %v", schedules.Entries())

	return nil
}
コード例 #4
0
ファイル: notification.go プロジェクト: sethjback/gobl
// Notify send the actual data to Cooridnator
// No guarantee that the data will be sent sequentually if errors occur when making the attempts
func (n *Queue) notify() {
	log.Info("notification", "Notify started")
	t := try.New(3)
	timeoutNum := 1
	var waitTime time.Duration
notify:
	for {
		select {
		case msg, ok := <-n.next:
			if !ok {
				//next was closed, we are done
				n.Finished <- true
				break notify
			}

			err := t.Do(func(attempt int) (bool, error) {
				sig, err := n.keyManager.Sign(string(msg.Payload))
				if err != nil {
					//log error
					log.Errorf("notification", "Unable to sign message: %v", err)
					return false, err
				}
				req := &httpapi.APIRequest{Address: n.Coordinator.Address, Body: msg.Payload, Signature: sig}

				_, err = req.POST(msg.Endpoint)
				if err != nil {
					log.Errorf("notification", "Unable to notify: %v", err)
					return false, err
				}

				return false, nil
			})

			if try.IsMaxRetries(err) {

				//requeue the message
				n.In <- msg

				//Communication issues, sleep then try again
				if timeoutNum < 10 {
					waitTime = time.Second * time.Duration(timeoutNum*timeoutNum)
				} else if timeoutNum < 15 {
					waitTime = time.Minute * time.Duration(timeoutNum)
				} else if timeoutNum < 21 {
					waitTime = time.Minute * time.Duration(timeoutNum*timeoutNum)
				} else {
					waitTime = time.Hour * time.Duration(timeoutNum)
					timeoutNum--
				}

				n.waitTimer = time.NewTimer(waitTime)
				<-n.waitTimer.C
				timeoutNum++
			}
		case <-n.stop:
			//Quit
			log.Info("notify", "Notify received stop call")
			break notify
		}
	}
}