Example #1
0
func (s *Server) Automate(instID flux.InstanceID, service flux.ServiceID) error {
	inst, err := s.instancer.Get(instID)
	if err != nil {
		return err
	}
	ns, svc := service.Components()
	inst.LogEvent(ns, svc, serviceAutomated)
	if err := recordAutomated(inst, service, true); err != nil {
		return err
	}

	// Schedule an immediate check, so things feel snappy for the user.
	_, err = s.jobs.PutJob(instID, jobs.Job{
		// Key stops us getting two jobs for the same service
		Key: strings.Join([]string{
			jobs.AutomatedServiceJob,
			string(instID),
			string(service),
		}, "|"),
		Method: jobs.AutomatedServiceJob,
		Params: jobs.AutomatedServiceJobParams{
			ServiceSpec: flux.ServiceSpec(service),
		},
		Priority: jobs.PriorityBackground,
	})
	if err == jobs.ErrJobAlreadyQueued {
		// Ignore this error, we're already doing it!
		err = nil
	}
	return err
}
Example #2
0
func (a *Automator) checkAll(errorLogger log.Logger) {
	insts, err := a.cfg.InstanceDB.All()
	if err != nil {
		errorLogger.Log("err", err)
		return
	}
	for _, inst := range insts {
		for service, conf := range inst.Config.Services {
			if conf.Policy() != flux.PolicyAutomated {
				continue
			}
			_, err := a.cfg.Jobs.PutJob(inst.ID, jobs.Job{
				// Key stops us getting two jobs for the same service
				Key: strings.Join([]string{
					jobs.AutomatedServiceJob,
					string(inst.ID),
					string(service),
				}, "|"),
				Method:   jobs.AutomatedServiceJob,
				Priority: jobs.PriorityBackground,
				Params: jobs.AutomatedServiceJobParams{
					ServiceSpec: flux.ServiceSpec(service),
				},
			})
			if err != nil && err != jobs.ErrJobAlreadyQueued {
				errorLogger.Log("err", errors.Wrapf(err, "queueing automated service job"))
			}
		}
	}
}