Skip to content

Commit

Permalink
refactor: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Jul 23, 2024
1 parent f4bbaec commit f6328a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/Jobs/WikiEntityImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public function handle(Client $kubernetesClient): void
$import = WikiEntityImport::findOrFail($this->importId);
$creds = $this->acquireCredentials($wiki->domain);

$this->targetWikiUrl = str_contains($wiki->domain, "localhost")
? "http://".$wiki->domain
: "https://".$wiki->domain;
$this->targetWikiUrl = $this->domainToOrigin($wiki->domain);

$kubernetesJob = new TransferBotKubernetesJob(
kubernetesClient: $kubernetesClient,
Expand All @@ -74,6 +72,14 @@ public function handle(Client $kubernetesClient): void
}
}

private static function domainToOrigin(string $domain): string
{
$tld = last(explode('.', $domain));
return $tld === 'localhost'
? "http://".$domain
: "https://".$domain;
}

private static function acquireCredentials(string $wikiDomain): OAuthCredentials
{
$response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post(
Expand Down Expand Up @@ -112,9 +118,13 @@ public function __construct(
public int $importId,
){
$this->kubernetesNamespace = Config::get('wbstack.api_job_namespace');
$this->transferbotImageRepo = Config::get('wbstack.transferbot_image_repo');
$this->transferbotImageVersion = Config::get('wbstack.transferbot_image_version');
}

private string $kubernetesNamespace;
private string $transferbotImageRepo;
private string $transferbotImageVersion;

public function spawn(): string
{
Expand Down Expand Up @@ -150,14 +160,14 @@ private function constructSpec(): array
'backoffLimit' => 0,
'template' => [
'metadata' => [
'name' => 'run-transferbot'
'name' => 'run-entity-import'
],
'spec' => [
'containers' => [
0 => [
'hostNetwork' => true,
'name' => 'run-qs-updater',
'image' => 'ghcr.io/wbstack/transferbot:1.0.0',
'name' => 'run-entity-import',
'image' => $this->transferbotImageRepo.':'.$this->transferbotImageVersion,
'env' => [
...$this->creds->marshalEnv(),
[
Expand Down
3 changes: 3 additions & 0 deletions config/wbstack.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@

'api_job_namespace' => env('API_JOB_NAMESPACE', env('WBSTACK_API_JOB_NAMESPACE', 'api-jobs')),
'qs_job_namespace' => env('WBSTACK_QS_JOB_NAMESPACE', 'qs-jobs'),

'transferbot_image_repo' => env('WBSTACK_TRANSFERBOT_IMAGE_REPO', 'ghcr.io/wbstack/transferbot'),
'transferbot_image_version' => env('WBSTACK_TRANSFERBOT_IMAGE_VERSION', '1.0.0'),
];

0 comments on commit f6328a1

Please sign in to comment.