mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
48
app/Jobs/CronJob/AddToServer.php
Normal file
48
app/Jobs/CronJob/AddToServer.php
Normal 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,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
46
app/Jobs/CronJob/RemoveFromServer.php
Normal file
46
app/Jobs/CronJob/RemoveFromServer.php
Normal 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,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user