Skip to content

Commit

Permalink
Fix/job container (#1350)
Browse files Browse the repository at this point in the history
* Fix old job container and esi requests

* Fix styling

* remove non-necessary method

---------

Co-authored-by: herpaderpaldent <[email protected]>
  • Loading branch information
herpaderpaldent and herpaderpaldent authored Mar 16, 2023
1 parent 6876480 commit 12c1fbd
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 89 deletions.
22 changes: 0 additions & 22 deletions resources/js/Shared/Components/SlideOver/DispatchUpdate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ import InfiniteLoadingHelper from "@/Shared/InfiniteLoadingHelper.vue";
export default {
name: "DispatchUpdate",
components: {InfiniteLoadingHelper, DispatchableEntry},
data: function () {
return {
//job_name: this.$page.props.dispatch_transfer_object.manual_job,
//dispatch_transfer_object: this.$page.props.dispatch_transfer_object,
entities: [],
infiniteId: new Date()
}
},
computed: {
dispatch_transfer_object() {
return this.$page.props.dispatch_transfer_object != null ? this.$page.props.dispatch_transfer_object : this.$page.props.dispatchTransferObject
Expand All @@ -39,13 +31,6 @@ export default {
return _.get(this.dispatch_transfer_object, 'manual_job')
}
},
created() {
/*if(!this.dispatch_transfer_object)
this.dispatch_transfer_object = this.$page.props.dispatchTransferObject*/
this.getEntities();
},
methods: {
dispatchJob(entity) {
Expand All @@ -58,14 +43,7 @@ export default {
}), {
dispatch_transfer_object: this.dispatch_transfer_object
})
setTimeout(() => this.getEntities(), 100)
}
}
}
</script>

<style scoped>
</style>
175 changes: 175 additions & 0 deletions src/Contracts/WebJobsRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php

namespace Seatplus\Web\Contracts;

use Seatplus\Eveapi\Jobs\Assets\CharacterAssetJob;
use Seatplus\Eveapi\Jobs\Assets\CharacterAssetsNameJob;
use Seatplus\Eveapi\Jobs\Contacts\AllianceContactJob;
use Seatplus\Eveapi\Jobs\Contacts\AllianceContactLabelJob;
use Seatplus\Eveapi\Jobs\Contacts\CharacterContactJob;
use Seatplus\Eveapi\Jobs\Contacts\CharacterContactLabelJob;
use Seatplus\Eveapi\Jobs\Contacts\CorporationContactJob;
use Seatplus\Eveapi\Jobs\Contacts\CorporationContactLabelJob;
use Seatplus\Eveapi\Jobs\Contracts\CharacterContractsJob;
use Seatplus\Eveapi\Jobs\Corporation\CorporationMemberTrackingJob;
use Seatplus\Eveapi\Jobs\Mail\MailHeaderJob;
use Seatplus\Eveapi\Jobs\Skills\SkillsJob;
use Seatplus\Eveapi\Jobs\Wallet\CharacterBalanceJob;
use Seatplus\Eveapi\Jobs\Wallet\CharacterWalletJournalJob;
use Seatplus\Eveapi\Jobs\Wallet\CharacterWalletTransactionJob;
use Seatplus\Eveapi\Jobs\Wallet\CorporationBalanceJob;
use Seatplus\Eveapi\Jobs\Wallet\CorporationWalletJournalJob;
use Seatplus\Eveapi\Models\RefreshToken;

class WebJobsRepository
{
private array $jobs = [];

public function __construct()
{
$this->jobs = [
// Character
'contacts' => fn (RefreshToken $refresh_token) => $this->getContactJobs($refresh_token),
'assets' => fn (RefreshToken $refresh_token) => $this->getAssetJobs($refresh_token),
'wallet' => fn (RefreshToken $refresh_token) => $this->getWalletJobs($refresh_token),
'contract' => fn (RefreshToken $refresh_token) => $this->getContractJobs($refresh_token),
'skills' => fn (RefreshToken $refresh_token) => $this->getSkillsJobs($refresh_token),
'mails' => fn (RefreshToken $refresh_token) => $this->getMailsJobs($refresh_token),
// Corporation
'corporation.wallet' => fn (RefreshToken $refresh_token) => $this->getCorporationWalletJobs($refresh_token),
'membertracking' => fn (RefreshToken $refresh_token) => $this->getCorporationWalletJobs($refresh_token),
];
}

public function addJob(string $key, \Closure $build_function): void
{
$this->jobs[$key] = $build_function;
}

public function addJobs(array $jobs): void
{
$this->jobs = array_merge($this->jobs, $jobs);
}

public function getJobKeys(): array
{
return array_keys($this->jobs);
}

public function getConstructedJobs(string $key, RefreshToken $refresh_token): array
{
return $this->jobs[$key]($refresh_token);
}

private function getContactJobs(RefreshToken $refresh_token): array
{
$jobs = [];

// if refresh token has scope for reading contacts add the job to the jobs array
if ($refresh_token->hasScope('esi-characters.read_contacts.v1')) {
$jobs[] = [
new CharacterContactJob($refresh_token->character_id),
new CharacterContactLabelJob($refresh_token->character_id),
];
}

// if refresh token has scope for reading corporation contacts add the job to the jobs array
if ($refresh_token->hasScope('esi-corporations.read_contacts.v1')) {
$jobs[] = [
new CorporationContactJob($refresh_token->character_id),
new CorporationContactLabelJob($refresh_token->character_id),
];
}

// if refresh token has scope for reading alliance contacts add the job to the jobs array
if ($refresh_token->hasScope('esi-alliances.read_contacts.v1')) {
$jobs[] = [
new AllianceContactJob($refresh_token->character_id),
new AllianceContactLabelJob($refresh_token->character_id),
];
}

return $jobs;
}

private function getAssetJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-assets.read_assets.v1')) {
return [];
}

return [
new CharacterAssetJob($refresh_token->character_id),
new CharacterAssetsNameJob($refresh_token->character_id),
];
}

private function getWalletJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-wallet.read_character_wallet.v1')) {
return [];
}

return [
new CharacterWalletJournalJob($refresh_token->character_id),
new CharacterWalletTransactionJob($refresh_token->character_id),
new CharacterBalanceJob($refresh_token->character_id),
];
}

private function getContractJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-contracts.read_character_contracts.v1')) {
return [];
}

return [
new CharacterContractsJob($refresh_token->character_id),
];
}

private function getSkillsJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-skills.read_skills.v1')) {
return [];
}

return [
new SkillsJob($refresh_token->character_id),
];
}

private function getMailsJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-mail.read_mail.v1')) {
return [];
}

return [
new MailHeaderJob($refresh_token->character_id),
];
}

private function getCorporationWalletJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-wallet.read_corporation_wallets.v1')) {
return [];
}

return [
new CorporationWalletJournalJob($refresh_token->corporation_id),
new CorporationBalanceJob($refresh_token->corporation_id),
];
}

public function getCorporationMemberTrackingJobs(RefreshToken $refresh_token): array
{
if (! $refresh_token->hasScope('esi-corporations.track_members.v1')) {
return [];
}

return [
new CorporationMemberTrackingJob($refresh_token->corporation_id),
];
}
}
16 changes: 9 additions & 7 deletions src/Http/Controllers/Queue/DispatchJobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Bus;
use Seatplus\Auth\Services\Dtos\AffiliationsDto;
use Seatplus\Eveapi\Containers\JobContainer;
use Seatplus\Eveapi\Models\RefreshToken;
use Seatplus\Eveapi\Services\FindCorporationRefreshToken;
use Seatplus\Web\Contracts\WebJobsRepository;
use Seatplus\Web\Http\Controllers\Controller;
use Seatplus\Web\Http\Controllers\Request\DispatchIndividualJob;
use Seatplus\Web\Jobs\ManualDispatchedJob;
Expand All @@ -42,26 +42,28 @@ class DispatchJobController extends Controller
{
protected array $dispatch_transfer_object;

public function __construct(
private WebJobsRepository $web_jobs
) {
}

public function dispatch(DispatchIndividualJob $job)
{
$this->dispatch_transfer_object = $job->get('dispatch_transfer_object');

$id = $job->get('character_id') ?? $job->get('corporation_id');
$manual_job = Arr::get($this->dispatch_transfer_object, 'manual_job');

$cache_key = $this->getCacheKey(Arr::get($this->dispatch_transfer_object, 'manual_job'), $id);
$cache_key = "${manual_job}:${id}";

if (cache($cache_key)) {
return redirect()->back()->with('error', 'job was already queued');
}

$hydrate_job_string = config('web.jobs.' . Arr::get($this->dispatch_transfer_object, 'manual_job'));
$job_container = new JobContainer(['refresh_token' => $this->getRefreshToken($job)]);

$hydrate_job = new $hydrate_job_string($job_container);
$batch_name = sprintf('Manual batch update of %s', $cache_key);

$batch_id = (new ManualDispatchedJob)
->setJobs([$hydrate_job])
->setJobs($this->web_jobs->getConstructedJobs($manual_job, $this->getRefreshToken($job)))
->setName($batch_name)
->handle();

Expand Down
10 changes: 5 additions & 5 deletions src/Http/Controllers/Shared/HelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ public function getMarketsPrices()
return $prices->toJson();
}

$container = new EsiRequestContainer([
'method' => 'get',
'version' => 'v1',
'endpoint' => '/markets/prices/',
]);
$container = new EsiRequestContainer(
method: 'get',
version: 'v1',
endpoint: '/markets/prices/',
);

$esi_results = RetrieveEsiData::execute($container);

Expand Down
18 changes: 4 additions & 14 deletions src/Services/DispatchCorporationOrAllianceInfoJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace Seatplus\Web\Services;

use Seatplus\Eveapi\Containers\JobContainer;
use Seatplus\Eveapi\Jobs\Alliances\AllianceInfoJob;
use Seatplus\Eveapi\Jobs\Corporation\CorporationInfoJob;
use Seatplus\Eveapi\Models\Alliance\AllianceInfo;
Expand All @@ -35,18 +34,9 @@ class DispatchCorporationOrAllianceInfoJob
{
public function handle(string $type, int $id)
{
$type === AllianceInfo::class ? $this->handleAllianceInfo($id) : $this->handleCorporationInfo($id);
}

private function handleAllianceInfo(int $entity_id)
{
$job_container = new JobContainer(['alliance_id' => $entity_id]);
AllianceInfoJob::dispatchSync($job_container);
}

private function handleCorporationInfo(int $entity_id)
{
$job_container = new JobContainer(['corporation_id' => $entity_id]);
CorporationInfoJob::dispatchSync($job_container);
match ($type) {
AllianceInfo::class => AllianceInfoJob::dispatchSync($id),
default => CorporationInfoJob::dispatchSync($id),
};
}
}
12 changes: 6 additions & 6 deletions src/Services/GetCharacterAffiliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class GetCharacterAffiliations
{
public function execute(array $character_ids): Collection
{
$character_affiliation_container = new EsiRequestContainer([
'method' => 'post',
'version' => 'v1',
'endpoint' => '/characters/affiliation/',
'request_body' => $character_ids,
]);
$character_affiliation_container = new EsiRequestContainer(
method: 'post',
version: 'v1',
endpoint: '/characters/affiliation/',
request_body: $character_ids,
);

$character_affiliations = RetrieveEsiData::execute($character_affiliation_container);

Expand Down
12 changes: 6 additions & 6 deletions src/Services/GetCorporationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class GetCorporationInfo
{
public function execute($corporation_id)
{
$corporation_info_container = new EsiRequestContainer([
'method' => 'get',
'version' => 'v4',
'endpoint' => '/corporations/{corporation_id}/',
'path_values' => ['corporation_id' => $corporation_id],
]);
$corporation_info_container = new EsiRequestContainer(
method: 'get',
version: 'v4',
endpoint: '/corporations/{corporation_id}/',
path_values: ['corporation_id' => $corporation_id],
);

return RetrieveEsiData::execute($corporation_info_container);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Services/GetIdsFromNamesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function execute(array $names): Collection
return $this->result;
}

$container = new EsiRequestContainer([
'method' => 'post',
'version' => 'v1',
'endpoint' => '/universe/ids/',
'request_body' => [...$names_to_resolve->toArray()],
]);
$container = new EsiRequestContainer(
method: 'post',
version: 'v1',
endpoint: '/universe/ids/',
request_body: [...$names_to_resolve->toArray()],
);

$esi_results = RetrieveEsiData::execute($container);

Expand Down
12 changes: 6 additions & 6 deletions src/Services/GetNamesFromIdsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public function execute(array $ids): Collection
return $this->result;
}

$container = new EsiRequestContainer([
'method' => 'post',
'version' => 'v3',
'endpoint' => '/universe/names/',
'request_body' => [...$ids_to_resolve->toArray()],
]);
$container = new EsiRequestContainer(
method: 'post',
version: 'v3',
endpoint: '/universe/names/',
request_body: [...$ids_to_resolve->toArray()],
);

$esi_results = RetrieveEsiData::execute($container);

Expand Down
Loading

0 comments on commit 12c1fbd

Please sign in to comment.