// Downgrade the TaskEvent payload (i.e. Task(s)) to the given target version
355839
func VersionTaskDefinitionsTo(event Event, target format.Version) Event {
	switch event := event.(type) {
	case *TaskCreatedEvent:
		return NewTaskCreatedEvent(event.Task.VersionDownTo(target))
	case *TaskRemovedEvent:
		return NewTaskRemovedEvent(event.Task.VersionDownTo(target))
	case *TaskChangedEvent:
		return NewTaskChangedEvent(event.Before.VersionDownTo(target), event.After.VersionDownTo(target))
	default:
		return event
	}
}
496526
func (s *EventStore) RenameEvent(ctx context.Context, from, to eh.EventType) error {
	sess := s.session.Copy()
	defer sess.Close()

	// Find and rename all events.
	// TODO: Maybe use change info.
	if _, err := sess.DB(s.dbName(ctx)).C("events").UpdateAll(
		bson.M{
			"events.event_type": string(from),
		},
		bson.M{
			"$set": bson.M{"events.$.event_type": string(to)},
		},
	); err != nil {
		return eh.EventStoreError{
			BaseErr:   err,
			Err:       ErrCouldNotSaveAggregate,
			Namespace: eh.NamespaceFromContext(ctx),
		}
	}

	return nil
}
495621
func (r *Renderer) RenderEvents(eventCh <-chan *TaskEvent) {
	for event := range eventCh {
		r.RenderEvent(event)
	}
}
617732
func (s *DirectMessageService) EventsNew(params *DirectMessageEventsNewParams) (*DirectMessageEvent, *http.Response, error) {
	// Twitter API wraps the event response
	wrap := &struct {
		Event *DirectMessageEvent `json:"event"`
	}{}
	apiError := new(APIError)
	resp, err := s.sling.New().Post("events/new.json").BodyJSON(params).Receive(wrap, apiError)
	return wrap.Event, resp, relevantError(err, *apiError)
}
935808
func (s *CompatibleVersionsMap) SetTargetVersions(v []*string) *CompatibleVersionsMap {
	s.TargetVersions = v
	return s
}
681200
func (c *DefaultClient) PublishDeviceEvent(appID string, devID string, eventType types.EventType, payload interface{}) Token {
	topic := DeviceTopic{appID, devID, DeviceEvents, string(eventType)}
	msg, err := json.Marshal(payload)
	if err != nil {
		return &simpleToken{fmt.Errorf("Unable to marshal the message payload: %s", err)}
	}
	return c.publish(topic.String(), msg)
}
1154107
func (c *Client) UpdateEvent(e contract.Event) (err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	id := e.ID

	o, err := eventByID(conn, id)
	if err != nil {
		if err == redis.ErrNil {
			return db.ErrNotFound
		}
		return err
	}

	e.Modified = db.MakeTimestamp()
	err = mergo.Merge(&e, o)
	if err != nil {
		return err
	}

	err = deleteEvent(conn, id)
	if err != nil {
		return err
	}

	_, err = addEvent(conn, e)
	return err
}
73149
func (i *instanceManager) dispenseTaskEventsCh() (<-chan *drivers.TaskEvent, context.CancelFunc, error) {
	driver, err := i.dispense()
	if err != nil {
		return nil, nil, err
	}

	ctx, cancel := context.WithCancel(i.ctx)
	eventsCh, err := driver.TaskEvents(ctx)
	if err != nil {
		cancel()
		return nil, nil, err
	}

	return eventsCh, cancel, nil
}
1178574
func (sc *StubController) Update(ctx context.Context, t *api.Task) error {
	sc.called()
	return sc.UpdateFn(ctx, t)
}
1202086
func (a *InvitationAggregate) ApplyEvent(ctx context.Context, event eh.Event) error {
	switch event.EventType() {
	case InviteCreatedEvent:
		if data, ok := event.Data().(*InviteCreatedData); ok {
			a.name = data.Name
			a.age = data.Age
		} else {
			log.Println("invalid event data type:", event.Data())
		}
	case InviteAcceptedEvent:
		a.accepted = true
	case InviteDeclinedEvent:
		a.declined = true
	case InviteConfirmedEvent:
		a.confirmed = true
	case InviteDeniedEvent:
		a.denied = true
	}
	return nil
}
1086841
func (mc MongoClient) UpdateEvent(e contract.Event) error {
	var mapped models.Event
	id, err := mapped.FromContract(e, mc)
	if err != nil {
		return err
	}

	mapped.TimestampForUpdate()

	return mc.updateId(db.EventsCollection, id, mapped)
}
1168367
func (t *UpdateTaskRequest) UpdateFlux(oldFlux string) error {
	if t.Options.IsZero() {
		return nil
	}
	tu := platform.TaskUpdate{
		Options: t.Options,
		Flux:    &t.Script,
	}
	if err := tu.UpdateFlux(oldFlux); err != nil {
		return err
	}
	t.Script = *tu.Flux
	t.Options.Clear()
	return nil
}
534179
func Convert_image_TagEvent_To_v1_TagEvent(in *image.TagEvent, out *v1.TagEvent, s conversion.Scope) error {
	return autoConvert_image_TagEvent_To_v1_TagEvent(in, out, s)
}
522690
func (mc MongoClient) EventsOlderThanAge(age int64) ([]contract.Event, error) {
	expireDate := (db.MakeTimestamp()) - age
	return mc.mapEvents(mc.getEvents(bson.M{"created": bson.M{"$lt": expireDate}}))
}
843690
func Convert_v1_GenericWebHookEvent_To_build_GenericWebHookEvent(in *v1.GenericWebHookEvent, out *build.GenericWebHookEvent, s conversion.Scope) error {
	return autoConvert_v1_GenericWebHookEvent_To_build_GenericWebHookEvent(in, out, s)
}
871647
func (s *Server) sendShutdownEvent() {
	s.mu.Lock()
	if s.sys == nil || s.sys.sendq == nil {
		s.mu.Unlock()
		return
	}
	subj := fmt.Sprintf(shutdownEventSubj, s.info.ID)
	sendq := s.sys.sendq
	// Stop any more messages from queueing up.
	s.sys.sendq = nil
	// Unhook all msgHandlers. Normal client cleanup will deal with subs, etc.
	s.sys.subs = nil
	s.mu.Unlock()
	// Send to the internal queue and mark as last.
	sendq <- &pubMsg{subj, _EMPTY_, nil, nil, true}
}
188272
func EventScore(e models.Event) int {
	lrp, crashed := getEventLRP(e)

	// sort crashed events first to be backward compatible with the old
	// event stream which emitted the crashed event before the
	// remove/changed events.
	if crashed {
		return 2
	}

	// this is an event with a running instance, this should be emitted before
	// any other event, such as removed ro changed event to non-running state.
	if lrp != nil && lrp.State == models.ActualLRPStateRunning {
		return 1
	}

	// The event is either a RemovedEvent or a ChangedEvent (to a non-RUNNING
	// state).  These are prioritized last, because those events cause loss of
	// routability.
	return 0
}