This commit is contained in:
Saeed Vaziry
2023-07-02 12:47:50 +02:00
commit 5c72f12490
825 changed files with 41659 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace App\Jobs\CronJob;
use App\Enums\CronjobStatus;
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand;
use Throwable;
class AddToServer extends Job
{
protected CronJob $cronJob;
public function __construct(CronJob $cronJob)
{
$this->cronJob = $cronJob;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$this->cronJob->server->ssh()->exec(
new UpdateCronJobsCommand($this->cronJob->user, $this->cronJob->crontab),
'update-crontab'
);
$this->cronJob->status = CronjobStatus::READY;
$this->cronJob->save();
event(
new Broadcast('add-cronjob-finished', [
'cronJob' => $this->cronJob,
])
);
}
public function failed(): void
{
$this->cronJob->delete();
event(
new Broadcast('add-cronjob-failed', [
'cronJob' => $this->cronJob,
])
);
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Jobs\CronJob;
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand;
use Throwable;
class RemoveFromServer extends Job
{
protected CronJob $cronJob;
public function __construct(CronJob $cronJob)
{
$this->cronJob = $cronJob;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$this->cronJob->server->ssh()->exec(
new UpdateCronJobsCommand($this->cronJob->user, $this->cronJob->crontab),
'update-crontab'
);
$this->cronJob->delete();
event(
new Broadcast('remove-cronjob-finished', [
'id' => $this->cronJob->id,
])
);
}
public function failed(): void
{
$this->cronJob->save();
event(
new Broadcast('remove-cronjob-failed', [
'cronJob' => $this->cronJob,
])
);
}
}