@@ -139,19 +139,22 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
139139 $ httpRequest ->setUrl ($ this ->getHandler ());
140140 $ httpRequest ->setHttpMethod (HttpMethod::POST );
141141
142+ $ payload = json_decode ($ payload , true );
143+
142144 // Laravel 7+ jobs have a uuid, but Laravel 6 doesn't have it.
143145 // Since we are using and expecting the uuid in some places
144146 // we will add it manually here if it's not present yet.
145- [ $ payload, $ uuid ] = $ this ->withUuid ($ payload );
147+ $ payload = $ this ->withUuid ($ payload );
146148
147149 // Since 3.x tasks are released back onto the queue after an exception has
148150 // been thrown. This means we lose the native [X-CloudTasks-TaskRetryCount] header
149151 // value and need to manually set and update the number of times a task has been attempted.
150152 $ payload = $ this ->withAttempts ($ payload );
151153
152- $ httpRequest ->setBody ($ payload );
154+ $ httpRequest ->setBody (json_encode ( $ payload) );
153155
154156 $ task = $ this ->createTask ();
157+ $ task ->setName ($ this ->taskName ($ queue , $ payload ));
155158 $ task ->setHttpRequest ($ httpRequest );
156159
157160 // The deadline for requests sent to the app. If the app does not respond by
@@ -174,34 +177,37 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
174177
175178 event ((new TaskCreated )->queue ($ queue )->task ($ task ));
176179
177- return $ uuid ;
180+ return $ payload [ ' uuid ' ] ;
178181 }
179182
180- private function withUuid (string $ payload ): array
183+ private function withUuid (array $ payload ): array
181184 {
182- /** @var array $decoded */
183- $ decoded = json_decode ($ payload , true );
184-
185- if (!isset ($ decoded ['uuid ' ])) {
186- $ decoded ['uuid ' ] = (string ) Str::uuid ();
185+ if (!isset ($ payload ['uuid ' ])) {
186+ $ payload ['uuid ' ] = (string ) Str::uuid ();
187187 }
188188
189- return [
190- json_encode ($ decoded ),
191- $ decoded ['uuid ' ],
192- ];
189+ return $ payload ;
193190 }
194191
195- private function withAttempts (string $ payload ): string
192+ private function taskName (string $ queueName , array $ payload ): string
196193 {
197- /** @var array $decoded */
198- $ decoded = json_decode ($ payload , true );
194+ $ displayName = str_replace ("\\" , '- ' , $ payload ['displayName ' ]);
195+
196+ return CloudTasksClient::taskName (
197+ $ this ->config ['project ' ],
198+ $ this ->config ['location ' ],
199+ $ queueName ,
200+ $ displayName . '- ' . $ payload ['uuid ' ]
201+ );
202+ }
199203
200- if (!isset ($ decoded ['internal ' ]['attempts ' ])) {
201- $ decoded ['internal ' ]['attempts ' ] = 0 ;
204+ private function withAttempts (array $ payload ): array
205+ {
206+ if (!isset ($ payload ['internal ' ]['attempts ' ])) {
207+ $ payload ['internal ' ]['attempts ' ] = 0 ;
202208 }
203209
204- return json_encode ( $ decoded ) ;
210+ return $ payload ;
205211 }
206212
207213 /**
0 commit comments