@@ -57,8 +57,8 @@ public function push($job, $data = '', $queue = null)
5757 $ this ->createPayload ($ job , $ queue , $ data ),
5858 $ queue ,
5959 null ,
60- function ($ payload , $ queue ) {
61- return $ this ->pushRaw ($ payload , $ queue );
60+ function ($ payload , $ queue ) use ( $ job ) {
61+ return $ this ->pushRaw ($ payload , $ queue, [ ' job ' => $ job ] );
6262 }
6363 );
6464 }
@@ -73,8 +73,9 @@ function ($payload, $queue) {
7373 public function pushRaw ($ payload , $ queue = null , array $ options = [])
7474 {
7575 $ delay = ! empty ($ options ['delay ' ]) ? $ options ['delay ' ] : 0 ;
76+ $ job = $ options ['job ' ] ?? null ;
7677
77- return $ this ->pushToCloudTasks ($ queue , $ payload , $ delay );
78+ return $ this ->pushToCloudTasks ($ queue , $ payload , $ delay, $ job );
7879 }
7980
8081 /**
@@ -93,8 +94,8 @@ public function later($delay, $job, $data = '', $queue = null)
9394 $ this ->createPayload ($ job , $ queue , $ data ),
9495 $ queue ,
9596 $ delay ,
96- function ($ payload , $ queue , $ delay ) {
97- return $ this ->pushToCloudTasks ($ queue , $ payload , $ delay );
97+ function ($ payload , $ queue , $ delay ) use ( $ job ) {
98+ return $ this ->pushToCloudTasks ($ queue , $ payload , $ delay, $ job );
9899 }
99100 );
100101 }
@@ -105,9 +106,10 @@ function ($payload, $queue, $delay) {
105106 * @param string|null $queue
106107 * @param string $payload
107108 * @param \DateTimeInterface|\DateInterval|int $delay
109+ * @param string|object $job
108110 * @return string
109111 */
110- protected function pushToCloudTasks ($ queue , $ payload , $ delay = 0 )
112+ protected function pushToCloudTasks ($ queue , $ payload , $ delay, mixed $ job )
111113 {
112114 $ queue = $ queue ?: $ this ->config ['queue ' ];
113115
@@ -122,7 +124,7 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
122124 connectionName: $ this ->getConnectionName (),
123125 );
124126
125- $ this ->addPayloadToTask ($ payload , $ task );
127+ $ this ->addPayloadToTask ($ payload , $ task, $ job );
126128
127129 // The deadline for requests sent to the app. If the app does not respond by
128130 // this deadline then the request is cancelled and the attempt is marked as
@@ -184,7 +186,8 @@ private function enrichPayloadWithInternalData(
184186 return $ payload ;
185187 }
186188
187- public function addPayloadToTask (array $ payload , Task $ task ): Task
189+ /** @param string|object $job */
190+ public function addPayloadToTask (array $ payload , Task $ task , mixed $ job ): Task
188191 {
189192 $ headers = value ($ this ->headers , $ payload ) ?: [];
190193
@@ -206,7 +209,7 @@ public function addPayloadToTask(array $payload, Task $task): Task
206209 $ task ->setAppEngineHttpRequest ($ appEngineRequest );
207210 } else {
208211 $ httpRequest = new HttpRequest ();
209- $ httpRequest ->setUrl ($ this ->getHandler ());
212+ $ httpRequest ->setUrl ($ this ->getHandler ($ job ));
210213 $ httpRequest ->setBody (json_encode ($ payload ));
211214 $ httpRequest ->setHttpMethod (HttpMethod::POST );
212215 $ httpRequest ->setHeaders ($ headers );
@@ -237,13 +240,18 @@ public function release(CloudTasksJob $job, int $delay = 0): void
237240
238241 $ payload = $ job ->getRawBody ();
239242
240- $ options = ['delay ' => $ delay ];
243+ $ options = ['delay ' => $ delay, ' job ' => $ job ];
241244
242245 $ this ->pushRaw ($ payload , $ job ->getQueue (), $ options );
243246 }
244247
245- public function getHandler (): string
248+ /** @param string|object $job */
249+ public function getHandler (mixed $ job ): string
246250 {
251+ if ($ job instanceof HasTaskHandlerUrl) {
252+ return $ job ->taskHandlerUrl ();
253+ }
254+
247255 if (empty ($ this ->config ['handler ' ])) {
248256 $ this ->config ['handler ' ] = request ()->getSchemeAndHttpHost ();
249257 }
0 commit comments