8
8
use Illuminate \Queue \Jobs \SqsJob ;
9
9
use Illuminate \Queue \SqsQueue ;
10
10
use Illuminate \Support \Facades \Config ;
11
+ use Illuminate \Support \Facades \Log ;
11
12
use Illuminate \Support \Str ;
12
13
use JsonException ;
13
14
use palPalani \SqsQueueReader \Jobs \DispatcherJob ;
@@ -119,13 +120,11 @@ private function modifySinglePayload(array | string $payload, string $class): ar
119
120
120
121
$ body = \json_decode ($ payload ['Body ' ], true , 512 , JSON_THROW_ON_ERROR );
121
122
122
- $ body = [
123
+ $ payload [ ' Body ' ] = \json_encode ( [
123
124
'uuid ' => (string ) Str::uuid (),
124
125
'job ' => $ class . '@handle ' ,
125
126
'data ' => $ body ['data ' ] ?? $ body ,
126
- ];
127
-
128
- $ payload ['Body ' ] = \json_encode ($ body , JSON_THROW_ON_ERROR );
127
+ ], JSON_THROW_ON_ERROR );
129
128
130
129
return $ payload ;
131
130
}
@@ -148,29 +147,33 @@ private function modifyMultiplePayload(array | string $payload, string $class):
148
147
$ receiptHandle = null ;
149
148
150
149
foreach ($ payload as $ k => $ item ) {
151
- $ body [$ k ] = [
152
- 'messages ' => \json_decode ($ item ['Body ' ], true , 512 , JSON_THROW_ON_ERROR ),
153
- 'attributes ' => $ item ['Attributes ' ],
154
- 'batchIds ' => [
155
- 'Id ' => $ item ['MessageId ' ],
156
- 'ReceiptHandle ' => $ item ['ReceiptHandle ' ],
157
- ],
158
- ];
159
- $ attributes = $ item ['Attributes ' ];
160
- $ messageId = $ item ['MessageId ' ];
161
- $ receiptHandle = $ item ['ReceiptHandle ' ];
150
+ try {
151
+ $ body [$ k ] = [
152
+ 'messages ' => \json_decode ($ item ['Body ' ], true , 512 , JSON_THROW_ON_ERROR ),
153
+ 'attributes ' => $ item ['Attributes ' ],
154
+ 'batchIds ' => [
155
+ 'Id ' => $ item ['MessageId ' ],
156
+ 'ReceiptHandle ' => $ item ['ReceiptHandle ' ],
157
+ ],
158
+ ];
159
+ $ attributes = $ item ['Attributes ' ];
160
+ $ messageId = $ item ['MessageId ' ];
161
+ $ receiptHandle = $ item ['ReceiptHandle ' ];
162
+ } catch (JsonException $ e ) {
163
+ Log::warning ('Invalid payload! ' , [$ item ]);
164
+
165
+ continue ;
166
+ }
162
167
}
163
168
164
- $ body = [
165
- 'uuid ' => (string ) Str::uuid (),
166
- 'job ' => $ class . '@handle ' ,
167
- 'data ' => $ body ,
168
- ];
169
-
170
169
return [
171
170
'MessageId ' => $ messageId ,
172
171
'ReceiptHandle ' => $ receiptHandle ,
173
- 'Body ' => \json_encode ($ body , JSON_THROW_ON_ERROR ),
172
+ 'Body ' => \json_encode ([
173
+ 'uuid ' => (string ) Str::uuid (),
174
+ 'job ' => $ class . '@handle ' ,
175
+ 'data ' => $ body ,
176
+ ], JSON_THROW_ON_ERROR ),
174
177
'Attributes ' => $ attributes ,
175
178
];
176
179
}
0 commit comments