@@ -12,6 +12,7 @@ class TaskHandler
1212{
1313 private $ request ;
1414 private $ publicKey ;
15+ private $ config ;
1516
1617 public function __construct (CloudTasksClient $ client , Request $ request , OpenIdVerificator $ publicKey )
1718 {
@@ -26,15 +27,27 @@ public function __construct(CloudTasksClient $client, Request $request, OpenIdVe
2627 */
2728 public function handle ($ task = null )
2829 {
29- $ this ->authorizeRequest ();
30-
3130 $ task = $ task ?: $ this ->captureTask ();
3231
32+ $ this ->loadQueueConnectionConfiguration ($ task );
33+
34+ $ this ->authorizeRequest ();
35+
3336 $ this ->listenForEvents ();
3437
3538 $ this ->handleTask ($ task );
3639 }
3740
41+ private function loadQueueConnectionConfiguration ($ task )
42+ {
43+ $ command = unserialize ($ task ['data ' ]['command ' ]);
44+ $ connection = $ command ->connection ?? config ('queue.default ' );
45+ $ this ->config = array_merge (
46+ config ("queue.connections. {$ connection }" ),
47+ ['connection ' => $ connection ]
48+ );
49+ }
50+
3851 /**
3952 * @throws CloudTasksException
4053 */
@@ -64,7 +77,7 @@ protected function validateToken($openIdToken)
6477 throw new CloudTasksException ('The given OpenID token is not valid ' );
6578 }
6679
67- if ($ openIdToken ->aud != Config:: handler () ) {
80+ if ($ openIdToken ->aud != $ this -> config [ ' handler ' ] ) {
6881 throw new CloudTasksException ('The given OpenID token is not valid ' );
6982 }
7083
@@ -97,7 +110,7 @@ private function listenForEvents()
97110 {
98111 app ('events ' )->listen (JobFailed::class, function ($ event ) {
99112 app ('queue.failer ' )->log (
100- ' cloudtasks ' , $ event ->job ->getQueue (),
113+ $ this -> config [ ' connection ' ] , $ event ->job ->getQueue (),
101114 $ event ->job ->getRawBody (), $ event ->exception
102115 );
103116 });
@@ -117,14 +130,14 @@ private function handleTask($task)
117130
118131 $ worker = $ this ->getQueueWorker ();
119132
120- $ worker ->process (' cloudtasks ' , $ job , new WorkerOptions ());
133+ $ worker ->process ($ this -> config [ ' connection ' ] , $ job , new WorkerOptions ());
121134 }
122135
123136 private function getQueueMaxTries (CloudTasksJob $ job )
124137 {
125138 $ queueName = $ this ->client ->queueName (
126- Config:: project () ,
127- Config:: location () ,
139+ $ this -> config [ ' project ' ] ,
140+ $ this -> config [ ' location ' ] ,
128141 $ job ->getQueue ()
129142 );
130143
0 commit comments