Пример #1
0
func (Ticker) Materialize() be.Reflex {
	reflex, eye := plumb.NewEye("Tick", "Duration")
	go func() {
		for {
			valve, value := eye.See()
			switch valve {
			case "Duration":
				dur := time.Duration(plumb.AsInt(value))
				if dur <= 0 {
					panic(4)
				}
				abr := make(chan struct{})
				go func() {
					start := time.Now()
					tkr := time.NewTicker(dur)
					defer tkr.Stop()
					for {
						select {
						case <-abr:
							return
						case t := <-tkr.C:
							eye.Show("Tick", int(t.Sub(start)))
						}
					}
				}()
			}
		}
	}()
	return reflex
}
Пример #2
0
//	Command example:
//
//		{
//			Image "ubuntu64"
//			Memory 10e9
//			CpuShares 23
//			Lxc {}
//			Volume {
//				"/haha"
//				"/mnt/all"
//			}
//			Entry "entrypoint"
//			Env {
//				"PATH=/abc:/bin"
//				"LESS=less"
//			}
//			Dir "/home/petar"
//			Path "/bin/ls"
//			Args { "-l", "/" }
//		}
//
func cognizeDockerCommand(v interface{}) *dkr.Run {
	img, ok := v.(Circuit)
	if !ok {
		panic(fmt.Sprintf("non-image sent as circuit container command (%v)", v))
	}
	cmd := &dkr.Run{}
	cmd.Image = img.StringAt("Image") // mandatory
	if mem, ok := img.IntOptionAt("Memory"); ok {
		cmd.Memory = int64(plumb.AsInt(mem))
	}
	if cpu, ok := img.IntOptionAt("CpuShares"); ok {
		cmd.CpuShares = int64(plumb.AsInt(cpu))
	}
	if lxc, ok := img.CircuitOptionAt("Lxc"); ok {
		for _, key := range lxc.Numbers() {
			cmd.Lxc = append(cmd.Lxc, lxc.StringAt(key))
		}
	}
	if vol, ok := img.CircuitOptionAt("Volume"); ok {
		for _, key := range vol.Numbers() {
			cmd.Volume = append(cmd.Volume, vol.StringAt(key))
		}
	}
	if entry, ok := img.StringOptionAt("Entry"); ok {
		cmd.Entry = entry
	}
	cmd.Path = img.StringAt("Path") // mandatory
	if dir, ok := img.StringOptionAt("Dir"); ok {
		cmd.Dir = dir
	}
	if env, ok := img.CircuitOptionAt("Env"); ok {
		for _, key := range env.Numbers() {
			cmd.Env = append(cmd.Env, env.StringAt(key))
		}
	}
	if args, ok := img.CircuitOptionAt("Args"); ok {
		for _, key := range args.Numbers() {
			cmd.Args = append(cmd.Args, args.StringAt(key))
		}
	}
	log.Printf("circuit docker command %v", QuickPrint("", "t", -1, img))
	return cmd
}
Пример #3
0
func (x *sum) Cognize(eye *plumb.Eye, dvalve string, dvalue interface{}) {
	x.save(dvalve, plumb.AsInt(dvalue))
	var wg sync.WaitGroup
	defer wg.Wait()
	wg.Add(2)
	switch dvalve {
	case "X":
		go func() { // Cognize
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Y", x.u("Sum")-x.u("X"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Sum", x.u("Y")+x.u("X"))
		}()
	case "Y":
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("X", x.u("Sum")-x.u("Y"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Sum", x.u("Y")+x.u("X"))
		}()
	case "Sum":
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("X", x.u("Sum")-x.u("Y"))
		}()
		go func() {
			defer func() {
				recover()
			}()
			defer wg.Done()
			eye.Show("Y", x.u("Sum")-x.u("X"))
		}()
	}
}
Пример #4
0
func (t *Delay) CognizeDuration(eye *be.Eye, value interface{}) {
	t.dur = time.Duration(plumb.AsInt(value))
}