Skip to content

Commit ad5d4f1

Browse files
authored
handle 404 error to avoid handling a not found resource continuously (#277)
Signed-off-by: Wei Liu <liuweixa@redhat.com>
1 parent cd947ff commit ad5d4f1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cmd/maestro/server/event_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ func broadcastStatusEvent(ctx context.Context,
269269
} else {
270270
resource, sErr = resourceService.Get(ctx, resourceID)
271271
if sErr != nil {
272+
if sErr.Is404() {
273+
log.Infof("skipping resource %s as it is not found", resource.ID)
274+
return nil
275+
}
272276
return fmt.Errorf("failed to get resource %s: %s", resourceID, sErr.Error())
273277
}
274278
}

pkg/client/cloudevents/source_client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ func NewSourceClient(sourceOptions *ceoptions.CloudEventsSourceOptions, resource
5959
func (s *SourceClientImpl) OnCreate(ctx context.Context, id string) error {
6060
resource, err := s.ResourceService.Get(ctx, id)
6161
if err != nil {
62+
if err.Is404() {
63+
log.Infof("skipping to publish create request for resource %s as it is not found", resource.ID)
64+
return nil
65+
}
66+
6267
return err
6368
}
6469

70+
if !resource.Meta.DeletedAt.Time.IsZero() {
71+
log.Infof("delete resource %s as it is not created on the agent yet", resource.ID)
72+
return s.ResourceService.Delete(ctx, id)
73+
}
74+
6575
log.Infof("Publishing resource %s for db row insert", resource.ID)
6676
eventType := cetypes.CloudEventsType{
6777
CloudEventsDataType: s.Codec.EventDataType(),
@@ -79,6 +89,10 @@ func (s *SourceClientImpl) OnCreate(ctx context.Context, id string) error {
7989
func (s *SourceClientImpl) OnUpdate(ctx context.Context, id string) error {
8090
resource, err := s.ResourceService.Get(ctx, id)
8191
if err != nil {
92+
if err.Is404() {
93+
log.Infof("skipping to publish update request for resource %s as it is not found", resource.ID)
94+
return nil
95+
}
8296
return err
8397
}
8498

@@ -99,6 +113,10 @@ func (s *SourceClientImpl) OnUpdate(ctx context.Context, id string) error {
99113
func (s *SourceClientImpl) OnDelete(ctx context.Context, id string) error {
100114
resource, err := s.ResourceService.Get(ctx, id)
101115
if err != nil {
116+
if err.Is404() {
117+
log.Infof("skipping to publish delete request for resource %s as it is not found", resource.ID)
118+
return nil
119+
}
102120
return err
103121
}
104122

0 commit comments

Comments
 (0)