push human readable milestone type

This commit is contained in:
Elio Bischof
2023-06-30 02:53:47 +02:00
parent 39e8e869ac
commit 5cacd0e996
3 changed files with 35 additions and 13 deletions

View File

@@ -2,7 +2,6 @@ package handlers
import (
"context"
"encoding/json"
"fmt"
"net/http"
@@ -77,17 +76,7 @@ func (t *telemetryPusher) reducers() []handler.AggregateReducer {
}}
}
// TODO: Remove
func printEvent(event eventstore.Event) {
bytes, err := json.MarshalIndent(event, "", " ")
if err != nil {
panic(err)
}
fmt.Println(event.Type(), string(bytes))
}
func (t *telemetryPusher) pushMilestones(event eventstore.Event) (*handler.Statement, error) {
printEvent(event)
ctx := call.WithTimestamp(context.Background())
scheduledEvent, ok := event.(*pseudo.ScheduledEvent)
if !ok {
@@ -133,7 +122,7 @@ func (t *telemetryPusher) pushMilestones(event eventstore.Event) (*handler.State
func (t *telemetryPusher) pushMilestone(ctx context.Context, event *pseudo.ScheduledEvent, ms *query.Milestone) error {
ctx = authz.WithInstanceID(ctx, ms.InstanceID)
alreadyHandled, err := t.queries.IsAlreadyHandled(ctx, event, map[string]interface{}{"type": ms.Type}, milestone.AggregateType, milestone.PushedEventType)
alreadyHandled, err := t.queries.IsAlreadyHandled(ctx, event, map[string]interface{}{"type": ms.Type.String()}, milestone.AggregateType, milestone.PushedEventType)
if err != nil {
return err
}

View File

@@ -194,7 +194,7 @@ func applyCustomConfig(config crdb.StatementHandlerConfig, customConfig CustomCo
// as setup and start currently create them individually, we make sure we get the right one
// will be refactored when changing to new id based projections
//
// Event handlers NotificationsProjection, NotificationsQuotaProjection and NotificationsProjection are not added here, because the do not statement based / have no proprietary projection table
// Event handlers NotificationsProjection, NotificationsQuotaProjection and NotificationsProjection are not added here, because they do not reduce to database statements
func newProjectionsList() {
projections = []projection{
OrgProjection,

View File

@@ -2,6 +2,11 @@
package milestone
import (
"fmt"
"strings"
)
type Type int
const (
@@ -24,3 +29,31 @@ func AllTypes() []Type {
}
return types
}
func (t *Type) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, t.String())), nil
}
func (t *Type) UnmarshalJSON(data []byte) error {
*t = typeFromString(strings.Trim(string(data), `"`))
return nil
}
func typeFromString(t string) Type {
switch t {
case InstanceCreated.String():
return InstanceCreated
case AuthenticationSucceededOnInstance.String():
return AuthenticationSucceededOnInstance
case ProjectCreated.String():
return ProjectCreated
case ApplicationCreated.String():
return ApplicationCreated
case AuthenticationSucceededOnApplication.String():
return AuthenticationSucceededOnApplication
case InstanceDeleted.String():
return InstanceDeleted
default:
return unknown
}
}