2022-04-21 10:37:39 +00:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2022-11-18 12:49:38 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
2022-04-26 23:01:45 +00: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 10:37:39 +00: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 12:49:38 +00:00
|
|
|
var lastFailed *timestamppb.Timestamp
|
|
|
|
if !failedEvent.LastFailed.IsZero() {
|
|
|
|
lastFailed = timestamppb.New(failedEvent.LastFailed)
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
return &system_pb.FailedEvent{
|
|
|
|
Database: failedEvent.Database,
|
|
|
|
ViewName: failedEvent.ViewName,
|
|
|
|
FailedSequence: failedEvent.FailedSequence,
|
|
|
|
FailureCount: failedEvent.FailureCount,
|
|
|
|
ErrorMessage: failedEvent.ErrMsg,
|
2022-11-18 12:49:38 +00:00
|
|
|
LastFailed: lastFailed,
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 14:33:50 +00:00
|
|
|
func FailedEventsToPb(database string, failedEvents *query.FailedEvents) []*system_pb.FailedEvent {
|
2022-04-21 10:37:39 +00:00
|
|
|
events := make([]*system_pb.FailedEvent, len(failedEvents.FailedEvents))
|
|
|
|
for i, failedEvent := range failedEvents.FailedEvents {
|
2022-05-31 14:33:50 +00:00
|
|
|
events[i] = FailedEventToPb(database, failedEvent)
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
2022-05-31 14:33:50 +00:00
|
|
|
func FailedEventToPb(database string, failedEvent *query.FailedEvent) *system_pb.FailedEvent {
|
2022-11-18 12:49:38 +00:00
|
|
|
var lastFailed *timestamppb.Timestamp
|
|
|
|
if !failedEvent.LastFailed.IsZero() {
|
|
|
|
lastFailed = timestamppb.New(failedEvent.LastFailed)
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
return &system_pb.FailedEvent{
|
2022-05-31 14:33:50 +00:00
|
|
|
Database: database,
|
2022-04-21 10:37:39 +00:00
|
|
|
ViewName: failedEvent.ProjectionName,
|
|
|
|
FailedSequence: failedEvent.FailedSequence,
|
|
|
|
FailureCount: failedEvent.FailureCount,
|
|
|
|
ErrorMessage: failedEvent.Error,
|
2022-11-18 12:49:38 +00:00
|
|
|
LastFailed: lastFailed,
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RemoveFailedEventRequestToModel(req *system_pb.RemoveFailedEventRequest) *model.FailedEvent {
|
|
|
|
return &model.FailedEvent{
|
|
|
|
Database: req.Database,
|
|
|
|
ViewName: req.ViewName,
|
|
|
|
FailedSequence: req.FailedSequence,
|
2022-11-18 12:49:38 +00:00
|
|
|
InstanceID: req.InstanceId,
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
|
|
|
}
|