Ejemplo n.º 1
0
func (srv *service) Forever(setup func() error) error {
	log.Printf("start service [%v]\n", os.Getpid())

	props := properties.Clone()
	log.Println("properties:")
	for _, k := range props.Keys() {
		log.Println(" ", k, props.Get(k))
	}

	err := setup()
	if err != nil {
		return err
	}
	log.Println("service setup successful")

	sigCh := make(chan os.Signal)
	signal.Notify(sigCh, os.Kill, os.Interrupt, syscall.SIGTERM)

	err = nil
	select {
	case <-sigCh:
	case err = <-registry.ErrorChannel():
	}

	close(registry.DoneChannel())
	registry.DoneWaitGroup().Wait()

	return err
}
Ejemplo n.º 2
0
func TestDelayTaskFailure(t *testing.T) {
	registry.DefaultServiceRegistry = registry.NewServiceRegistry()

	scheduler := NewFixedDelayScheduler(0, time.Second)

	scheduler.Schedule(func() error {
		return errors.New("asd")
	})

	err := <-registry.ErrorChannel()
	close(registry.DoneChannel())
	registry.DoneWaitGroup().Wait()

	if err.Error() != "asd" {
		t.Errorf("unexpected error %v", err.Error())
	}
}