Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
// 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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
// 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
		}
	}
}