@@ -59,9 +59,19 @@ func NewSourceClient(sourceOptions *ceoptions.CloudEventsSourceOptions, resource
5959func (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 {
7989func (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 {
99113func (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