2022-04-21 12:37:39 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2022-11-18 13:49:38 +01:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
|
|
"github.com/zitadel/zitadel/internal/view/model"
|
|
|
|
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
2022-04-21 12:37:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func FailedEventsViewToPb(failedEvents []*model.FailedEvent) []*system_pb.FailedEvent {
|
|
|
|
events := make([]*system_pb.FailedEvent, len(failedEvents))
|
|
|
|
for i, failedEvent := range failedEvents {
|
|
|
|
events[i] = FailedEventViewToPb(failedEvent)
|
|
|
|
}
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
|
|
|
func FailedEventViewToPb(failedEvent *model.FailedEvent) *system_pb.FailedEvent {
|
2022-11-18 13:49:38 +01:00
|
|
|
var lastFailed *timestamppb.Timestamp
|
|
|
|
if !failedEvent.LastFailed.IsZero() {
|
|
|
|
lastFailed = timestamppb.New(failedEvent.LastFailed)
|
|
|
|
}
|
2022-04-21 12:37:39 +02:00
|
|
|
return &system_pb.FailedEvent{
|
|
|
|
Database: failedEvent.Database,
|
|
|
|
ViewName: failedEvent.ViewName,
|
|
|
|
FailedSequence: failedEvent.FailedSequence,
|
|
|
|
FailureCount: failedEvent.FailureCount,
|
|
|
|
ErrorMessage: failedEvent.ErrMsg,
|
2022-11-18 13:49:38 +01:00
|
|
|
LastFailed: lastFailed,
|
2022-04-21 12:37:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:33:50 +02:00
|
|
|
func FailedEventsToPb(database string, failedEvents *query.FailedEvents) []*system_pb.FailedEvent {
|
2022-04-21 12:37:39 +02:00
|
|
|
events := make([]*system_pb.FailedEvent, len(failedEvents.FailedEvents))
|
|
|
|
for i, failedEvent := range failedEvents.FailedEvents {
|
2022-05-31 16:33:50 +02:00
|
|
|
events[i] = FailedEventToPb(database, failedEvent)
|
2022-04-21 12:37:39 +02:00
|
|
|
}
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:33:50 +02:00
|
|
|
func FailedEventToPb(database string, failedEvent *query.FailedEvent) *system_pb.FailedEvent {
|
2022-11-18 13:49:38 +01:00
|
|
|
var lastFailed *timestamppb.Timestamp
|
|
|
|
if !failedEvent.LastFailed.IsZero() {
|
|
|
|
lastFailed = timestamppb.New(failedEvent.LastFailed)
|
|
|
|
}
|
2022-04-21 12:37:39 +02:00
|
|
|
return &system_pb.FailedEvent{
|
2022-05-31 16:33:50 +02:00
|
|
|
Database: database,
|
2022-04-21 12:37:39 +02:00
|
|
|
ViewName: failedEvent.ProjectionName,
|
|
|
|
FailedSequence: failedEvent.FailedSequence,
|
|
|
|
FailureCount: failedEvent.FailureCount,
|
|
|
|
ErrorMessage: failedEvent.Error,
|
2022-11-18 13:49:38 +01:00
|
|
|
LastFailed: lastFailed,
|
2022-04-21 12:37:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RemoveFailedEventRequestToModel(req *system_pb.RemoveFailedEventRequest) *model.FailedEvent {
|
|
|
|
return &model.FailedEvent{
|
|
|
|
Database: req.Database,
|
|
|
|
ViewName: req.ViewName,
|
|
|
|
FailedSequence: req.FailedSequence,
|
2022-11-18 13:49:38 +01:00
|
|
|
InstanceID: req.InstanceId,
|
2022-04-21 12:37:39 +02:00
|
|
|
}
|
|
|
|
}
|