// sendEventToSink transforms buildPayload to CloudEvent, then try to send to sink.
sendEventToSink transforms buildPayload to CloudEvent, then try to send to sink.
// sendEventToSink transforms buildPayload to CloudEvent then try to send to sink .
func (a *Adapter) sendEventToSink(payload dockerhub.BuildPayload) error {
	cloudEventType := v1alpha1.DockerHubCloudEventsEventType(resources.DockerHubEventType)
	cloudEventSource := v1alpha1.DockerHubEventSource(payload.Repository.RepoName)
	cloudEventTime, err := getTime(payload.PushData.PushedAt)
	if err != nil {
		a.logger.Warnf("failed to parse pushedAt field. Use time.Now(): %v", err)
	}
	ctx := cloudevents.ContextWithRetriesExponentialBackoff(context.Background(), 50*time.Millisecond, 5)
	event := cloudevents.NewEvent()
	event.SetID(uuid.NewString())
	event.SetType(cloudEventType)
	event.SetSource(cloudEventSource)
	event.SetTime(cloudEventTime)
	event.SetSubject(payload.PushData.Pusher)
	event.SetExtension("tag", payload.PushData.Tag)
	err = event.SetData(cloudevents.ApplicationJSON, payload)
	if err != nil {
		return fmt.Errorf("failed to marshal buildPayload :%v", err)
	}
	a.logger.Infof("Sending event: %v", event)
	result := a.client.Send(ctx, event)
	if cloudevents.IsUndelivered(result) {
		return fmt.Errorf("the event is not delivered: %v", result)
	}
	return nil
}
func ( a * Adapter ) sendEventToSink ( payload dockerhub . BuildPayload ) error { cloudEventType := v1alpha1 . DockerHubCloudEventsEventType ( resources . DockerHubEventType ) cloudEventSource := v1alpha1 . DockerHubEventSource ( payload . Repository . RepoName ) cloudEventTime , err := getTime ( payload . PushData . PushedAt ) if err != nil { a . logger . Warnf ( " " , err ) } ctx := cloudevents . ContextWithRetriesExponentialBackoff ( context . Background ( ) , 50 * time . Millisecond , 5 ) event := cloudevents . NewEvent ( ) event . SetID ( uuid . NewString ( ) ) event . SetType ( cloudEventType ) event . SetSource ( cloudEventSource ) event . SetTime ( cloudEventTime ) event . SetSubject ( payload . PushData . Pusher ) event . SetExtension ( " " , payload . PushData . Tag ) err = event . SetData ( cloudevents . ApplicationJSON , payload ) if err != nil { return fmt . Errorf ( " " , err ) } a . logger . Infof ( " " , event ) result := a . client . Send ( ctx , event ) if cloudevents . IsUndelivered ( result ) { return fmt . Errorf ( " " , result ) } return nil }
sendEventToSink transforms buildPayload to CloudEvent, then try to send to sink.
sendEventToSink transforms buildPayload to CloudEvent then try to send to sink .
// if fail to send, retry with exponential backoff