Skip to content

Commit

Permalink
refactor a few jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Nov 7, 2024
1 parent 33519bf commit 2b518e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function schedule(Schedule $schedule): void
// Instance Jobs
$schedule->command('horizon:snapshot')->everyMinute();
$schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
$schedule->job(new CheckHelperImageJob)->everyFiveMinutes()->onOneServer();
$schedule->job(new CheckHelperImageJob)->everyTenMinutes()->onOneServer();

// Server Jobs
$this->checkResources($schedule);
Expand Down
30 changes: 9 additions & 21 deletions app/Jobs/CleanupInstanceStuffsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,37 @@
namespace App\Jobs;

use App\Models\TeamInvitation;
use App\Models\Waitlist;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class CleanupInstanceStuffsJob implements ShouldBeEncrypted, ShouldBeUnique, ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct() {}

// public function uniqueId(): string
// {
// return $this->container_name;
// }
public function middleware(): array
{
return [(new WithoutOverlapping('cleanup-instance-stuffs'))->dontRelease()];
}

public function handle(): void
{
try {
// $this->cleanup_waitlist();
} catch (\Throwable $e) {
send_internal_notification('CleanupInstanceStuffsJob failed with error: '.$e->getMessage());
}
try {
$this->cleanup_invitation_link();
$this->cleanupInvitationLink();
} catch (\Throwable $e) {
send_internal_notification('CleanupInstanceStuffsJob failed with error: '.$e->getMessage());
}
}

private function cleanup_waitlist()
{
$waitlist = Waitlist::whereVerified(false)->where('created_at', '<', now()->subMinutes(config('constants.waitlist.expiration')))->get();
foreach ($waitlist as $item) {
$item->delete();
Log::error('CleanupInstanceStuffsJob failed with error: '.$e->getMessage());
}
}

private function cleanup_invitation_link()
private function cleanupInvitationLink()
{
$invitation = TeamInvitation::all();
foreach ($invitation as $item) {
Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/DockerCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

Expand All @@ -23,6 +24,11 @@ class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueue

public ?string $usageBefore = null;

public function middleware(): array
{
return [(new WithoutOverlapping($this->server->id))->dontRelease()];
}

public function __construct(public Server $server, public bool $manualCleanup = false) {}

public function handle(): void
Expand Down

0 comments on commit 2b518e2

Please sign in to comment.