44
55use App \Http \Controllers \Controller ;
66use App \QsBatch ;
7+ use App \Services \MediaWikiHostResolver ;
8+ use App \Services \UnknownDBVersionException ;
9+ use App \Services \UnknownWikiDomainException ;
710use Carbon \Carbon ;
811use Illuminate \Http \Request ;
912use Illuminate \Http \Response ;
1013use Illuminate \Support \Facades \DB ;
14+ use Illuminate \Support \Facades \Log ;
1115
1216class QsController extends Controller {
13- public function getBatches (Request $ request ): Response {
14- return DB ::transaction (function () {
17+ public function getBatches (Request $ request, MediaWikiHostResolver $ mwHostResolver ): Response {
18+ return DB ::transaction (function () use ( $ mwHostResolver ) {
1519 $ oldestBatch = QsBatch ::has ('wiki ' )
1620 ->where ([
1721 ['done ' , '= ' , 0 ],
@@ -29,11 +33,31 @@ public function getBatches(Request $request): Response {
2933 $ oldestBatch ->update (['pending_since ' => Carbon ::now ()]);
3034 $ oldestBatch ->load (['wiki ' , 'wiki.wikiQueryserviceNamespace ' ]);
3135
36+ // queryservice-updater reads from MediaWiki directly
37+ // platform-nginx is bypassed, which does not serve suspended wikis
38+ $ oldestBatch ->setAttribute (
39+ 'mediawiki_backend_host ' ,
40+ $ this ->getMediaWikiBackendHost ($ mwHostResolver , $ oldestBatch )
41+ );
42+
3243 return response ([$ oldestBatch ]);
3344 }, 3 );
3445
3546 }
3647
48+ private function getMediaWikiBackendHost (MediaWikiHostResolver $ mwHostResolver , QsBatch $ batch ): ?string {
49+ try {
50+ // Resolving by domain avoids exposing wikiDb credentials in the response
51+ return $ mwHostResolver ->getBackendHostForDomain ($ batch ->wiki ->domain );
52+ } catch (UnknownDBVersionException |UnknownWikiDomainException $ e ) {
53+ Log ::warning ('Unable to resolve the MediaWiki backend host for queryservice batch ' . $ batch ->id . ': ' . $ e ->getMessage ());
54+
55+ // Keep an unknown host from blocking the queue by returning null
56+ // allowing the batch to proceed without a resolved backend host
57+ return null ;
58+ }
59+ }
60+
3761 public function markBatchesDone (Request $ request ): Response {
3862 $ batches = (array ) $ request ->json ()->all ('batches ' );
3963 QsBatch ::whereIn ('id ' , $ batches )->increment (
0 commit comments