Пример #1
0
// circuit mkproc /X1234/hola/charlie << EOF
// { … }
// EOF
// TODO: Proc element disappears if command misspelled and error condition not obvious.
func mkproc(x *cli.Context) {
	defer func() {
		if r := recover(); r != nil {
			fatalf("error, likely due to missing server or misspelled anchor: %v", r)
		}
	}()
	c := dial(x)
	args := x.Args()
	if len(args) != 1 {
		fatalf("mkproc needs an anchor argument")
	}
	w, _ := parseGlob(args[0])
	buf, _ := ioutil.ReadAll(os.Stdin)
	var cmd client.Cmd
	if err := json.Unmarshal(buf, &cmd); err != nil {
		fatalf("command json not parsing: %v", err)
	}
	if x.Bool("scrub") {
		cmd.Scrub = true
	}
	p, err := c.Walk(w).MakeProc(cmd)
	if err != nil {
		fatalf("mkproc error: %s", err)
	}
	ps := p.Peek()
	if ps.Exit != nil {
		fatalf("%v", ps.Exit)
	}
}
Пример #2
0
// AddJob adds a new job for scheduling.
// The name parameter must identify the job uniquely.
// The cmd parameter holds the execution specification for the job.
// An error is returned if a job with the same name is already in the scheduler.
func (s *Controller) AddJob(name string, cmd client.Cmd) error {
	s.Lock()
	defer s.Unlock()
	if _, present := s.job[name]; present {
		return fmt.Errorf("Duplicate job name.")
	}
	s.job[name] = struct{}{}
	log.Printf("Added job %s.", name)
	cmd.Scrub = true
	s.pending = append(s.pending, &job{name, cmd})
	go s.schedule()
	return nil
}