예제 #1
0
// newEventData returns the passed event as event data to collect.
func newEventData(event cells.Event) EventData {
	data := EventData{
		Topic:   event.Topic(),
		Payload: event.Payload(),
	}
	return data
}
예제 #2
0
// ProcessEvent reads, validates and emits a configuration.
func (b *configuratorBehavior) ProcessEvent(event cells.Event) error {
	switch event.Topic() {
	case ReadConfigurationTopic:
		// Read configuration
		filename, ok := event.Payload().GetString(ConfigurationFilenamePayload)
		if !ok {
			logger.Errorf("cannot read configuration without filename payload")
			return nil
		}
		logger.Infof("reading configuration from %q", filename)
		cfg, err := etc.ReadFile(filename)
		if err != nil {
			return errors.Annotate(err, ErrCannotReadConfiguration, errorMessages)
		}
		// If wanted then validate it.
		if b.validate != nil {
			err = b.validate(cfg)
			if err != nil {
				return errors.Annotate(err, ErrCannotValidateConfiguration, errorMessages)
			}
		}
		// All done, emit it.
		pvs := cells.PayloadValues{
			ConfigurationPayload: cfg,
		}
		b.cell.EmitNewContext(ConfigurationTopic, pvs, event.Context())
	}
	return nil
}
예제 #3
0
// cents retrieves the cents out of the payload of an event.
func payloadCents(event cells.Event) int {
	cents, ok := event.Payload().Get(cells.DefaultPayload)
	if !ok {
		return -1
	}
	return cents.(int)
}
예제 #4
0
// ProcessEvent calls a callback functions with the event data.
func (b *callbackBehavior) ProcessEvent(event cells.Event) error {
	for _, callbackFunc := range b.callbackFuncs {
		if err := callbackFunc(event.Topic(), event.Payload()); err != nil {
			return err
		}
	}
	return nil
}
예제 #5
0
// Configuration returns the configuration payload
// of the passed event or an empty configuration.
func Configuration(event cells.Event) etc.Etc {
	payload, ok := event.Payload().Get(ConfigurationPayload)
	if !ok {
		logger.Warningf("event does not contain configuration payload")
		cfg, _ := etc.ReadString("{etc}")
		return cfg
	}
	cfg, ok := payload.(etc.Etc)
	if !ok {
		logger.Warningf("configuration payload has illegal type")
		cfg, _ := etc.ReadString("{etc}")
		return cfg
	}
	return cfg
}
예제 #6
0
func (b *emitBehavior) ProcessEvent(event cells.Event) error {
	return b.c.EmitNew(sleepTopic, event.Payload())
}