Skip to content

Commit

Permalink
turn off most old git jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 10, 2024
1 parent 87e1462 commit 073ece6
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 65 deletions.
8 changes: 2 additions & 6 deletions app/Events/DeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
namespace App\Events;

use App\Models\Entity;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DeleteEntity
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public Entity $entity;

/**
* Create a new event instance.
*/
public function __construct(Entity $entity )
public function __construct(Entity $entity)
{
$this->entity = $entity;
}

}
4 changes: 0 additions & 4 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
namespace App\Http\Controllers;

use App\Http\Requests\StoreEntity;
use App\Jobs\GitAddEntity;
use App\Jobs\GitAddMember;
use App\Jobs\GitAddToCategory;
use App\Jobs\GitAddToEdugain;
use App\Jobs\GitAddToHfd;
use App\Jobs\GitAddToRs;
use App\Jobs\GitDeleteEntity;
use App\Jobs\GitDeleteFromCategory;
use App\Jobs\GitDeleteFromEdugain;
use App\Jobs\GitDeleteFromHfd;
use App\Jobs\GitDeleteFromRs;
use App\Jobs\GitRestoreToCategory;
use App\Jobs\GitRestoreToEdugain;
use App\Jobs\GitUpdateEntity;
use App\Ldap\CesnetOrganization;
use App\Ldap\EduidczOrganization;
use App\Mail\NewIdentityProvider;
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Http\Requests\StoreFederation;
use App\Http\Requests\UpdateFederation;
use App\Jobs\GitAddMembers;
use App\Jobs\GitDeleteMembers;
use App\Models\Entity;
use App\Models\Federation;
Expand Down Expand Up @@ -284,7 +283,9 @@ public function update(UpdateFederation $request, Federation $federation)
]);

$new_entities = Entity::whereIn('id', request('entities'))->get();
GitAddMembers::dispatch($federation, $new_entities, Auth::user());

//TODO add members to federation
// GitAddMembers::dispatch($federation, $new_entities, Auth::user());
Notification::send($federation->operators, new FederationMembersChanged($federation, $new_entities, 'added'));
Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $new_entities, 'added'));

Expand Down
31 changes: 15 additions & 16 deletions app/Http/Controllers/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;

use App\Jobs\GitAddEntity;
use App\Jobs\GitAddMembership;
use App\Jobs\GitAddToHfd;
use App\Models\Membership;
use App\Models\User;
Expand Down Expand Up @@ -41,20 +39,21 @@ public function update(Membership $membership)
$membership->update();
});

Bus::chain([
new GitAddEntity($membership->entity, Auth::user()),
new GitAddToHfd($membership->entity, Auth::user()),
new GitAddMembership($membership, Auth::user()),
function () use ($membership) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($membership->entity->operators, new MembershipAccepted($membership));
Notification::send($admins, new MembershipAccepted($membership));
if ($membership->entity->hfd) {
Notification::send($membership->entity->operators, new EntityAddedToHfd($membership->entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($membership->entity));
}
},
])->dispatch();
// TODO chain of update membership chain
/* Bus::chain([
new Old_GitAddEntity($membership->entity, Auth::user()),
new GitAddToHfd($membership->entity, Auth::user()),
new GitAddMembership($membership, Auth::user()),
function () use ($membership) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($membership->entity->operators, new MembershipAccepted($membership));
Notification::send($admins, new MembershipAccepted($membership));
if ($membership->entity->hfd) {
Notification::send($membership->entity->operators, new EntityAddedToHfd($membership->entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($membership->entity));
}
},
])->dispatch();*/

return redirect()
->back()
Expand Down
1 change: 0 additions & 1 deletion app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct(Entity $entity)
$this->entity = $entity;
}


/**
* Execute the job.
*/
Expand Down
5 changes: 0 additions & 5 deletions app/Jobs/FolderDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Facades\EntityFacade;
use App\Models\Entity;
use App\Models\Federation;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
Expand Down Expand Up @@ -56,11 +55,7 @@ public function handle(): void
}
}




}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitAddEntity implements ShouldQueue
class Old_GitAddEntity implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitAddMember implements ShouldQueue
class Old_GitAddMember implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitAddMembers implements ShouldQueue
class Old_GitAddMembers implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitAddMembership implements ShouldQueue
class Old_GitAddMembership implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitDeleteEntity implements ShouldQueue
class Old_GitDeleteEntity implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Illuminate\Support\Facades\Storage;
use Throwable;

class GitUpdateEntity implements ShouldQueue
class Old_GitUpdateEntity implements ShouldQueue
{
use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels;

Expand Down
7 changes: 1 addition & 6 deletions app/Listeners/SendDeletedEntityToDeleteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use App\Events\DeleteEntity;
use App\Facades\EntityFacade;
use App\Jobs\FolderDeleteEntity;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class SendDeletedEntityToDeleteJob
Expand All @@ -33,9 +31,6 @@ public function handle(DeleteEntity $event): void
EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id);
}




// FolderDeleteEntity::dispatch($event->entity);
// FolderDeleteEntity::dispatch($event->entity);
}
}
2 changes: 1 addition & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EventServiceProvider extends ServiceProvider
],
DeleteEntity::class => [
SendDeletedEntityToDeleteJob::class,
]
],

];

Expand Down
8 changes: 2 additions & 6 deletions app/Services/EntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,17 @@ public function saveEntityMetadataToFolder($entity_id, $folderName): void
public function deleteEntityMetadataFromFolder($fileName, $folderName): void
{
$diskName = config('storageCfg.name');
$pathToFile = $folderName . '/' . $fileName;
$pathToFile = $folderName.'/'.$fileName;

if (Storage::disk($diskName)->exists($pathToFile)) {
try {
Storage::disk($diskName)->delete($pathToFile);
} catch (Exception $e) {
Log::error("Failed to delete file: {$pathToFile}. Error: " . $e->getMessage());
Log::error("Failed to delete file: {$pathToFile}. Error: ".$e->getMessage());
}
} else {
Log::warning("File does not exist: {$pathToFile}");
}



}


}
3 changes: 0 additions & 3 deletions tests/Feature/Http/Controllers/EntityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Tests\Feature\Http\Controllers;

use App\Jobs\GitAddEntity;
use App\Jobs\GitDeleteEntity;
use App\Jobs\GitUpdateEntity;
use App\Models\Entity;
use App\Models\Federation;
use App\Models\Membership;
Expand Down
17 changes: 8 additions & 9 deletions tests/Feature/Http/Controllers/FederationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Feature\Http\Controllers;

use App\Jobs\GitAddMembers;
use App\Jobs\GitDeleteMembers;
use App\Jobs\GitUpdateFederation;
use App\Jobs\Old_GitAddFederation;
Expand Down Expand Up @@ -514,10 +513,10 @@ public function a_user_with_operator_permission_can_change_an_existing_federatio
$this->assertEquals(2, $federation->entities()->count());
$this->assertEquals(route('federations.entities', $federation), url()->current());

Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) {
return $job->federation->is($federation) &&
$job->entities->contains($new_entity);
});
/* Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) {
return $job->federation->is($federation) &&
$job->entities->contains($new_entity);
});*/

$this
->followingRedirects()
Expand Down Expand Up @@ -1086,10 +1085,10 @@ public function an_admin_can_change_an_existing_federations_entities()
$this->assertEquals(2, $federation->entities()->count());
$this->assertEquals(route('federations.entities', $federation), url()->current());

Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) {
return $job->federation->is($federation) &&
$job->entities->contains($new_entity);
});
/* Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) {
return $job->federation->is($federation) &&
$job->entities->contains($new_entity);
});*/

$this
->followingRedirects()
Expand Down

0 comments on commit 073ece6

Please sign in to comment.