mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-21 23:20:24 +00:00
update
This commit is contained in:
parent
60a57b6606
commit
d791dd3c8a
3 changed files with 31 additions and 64 deletions
|
@ -26,10 +26,23 @@ class Backup extends Model
|
|||
|
||||
static::creating(function ($model) {
|
||||
$model->status = 'pending';
|
||||
$model->checkCronJob();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function checkCronJob()
|
||||
{
|
||||
$findCronJob = CronJob::where('command', 'phyre-php artisan phyre:run-backup')->first();
|
||||
if (! $findCronJob) {
|
||||
$cronJob = new CronJob();
|
||||
$cronJob->schedule = '*/5 * * * *';
|
||||
$cronJob->command = 'phyre-php artisan phyre:run-backup';
|
||||
$cronJob->user = 'root';
|
||||
$cronJob->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function backupRelated() : Attribute
|
||||
{
|
||||
$relatedWith = $this->backup_type;
|
||||
|
|
|
@ -2,87 +2,45 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\ShellApi;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sushi\Sushi;
|
||||
|
||||
class CronJob extends Model
|
||||
{
|
||||
use Sushi;
|
||||
|
||||
protected $fillable = [
|
||||
'schedule',
|
||||
'command',
|
||||
'user',
|
||||
];
|
||||
|
||||
protected $schema = [
|
||||
'schedule' => 'string',
|
||||
'command' => 'string',
|
||||
'user' => 'string',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
|
||||
$addCron = ShellApi::callBin('cron-job-add', [
|
||||
$model->user,
|
||||
$model->schedule,
|
||||
$model->command,
|
||||
]);
|
||||
if (empty($addCron)) {
|
||||
return false;
|
||||
}
|
||||
// $addCron = ShellApi::callBin('cron-job-add', [
|
||||
// $model->user,
|
||||
// $model->schedule,
|
||||
// $model->command,
|
||||
// ]);
|
||||
// if (empty($addCron)) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
|
||||
$deleteCron = ShellApi::callBin('cron-job-delete', [
|
||||
$model->user,
|
||||
$model->schedule,
|
||||
$model->command,
|
||||
]);
|
||||
if (empty($deleteCron)) {
|
||||
return false;
|
||||
}
|
||||
// $deleteCron = ShellApi::callBin('cron-job-delete', [
|
||||
// $model->user,
|
||||
// $model->schedule,
|
||||
// $model->command,
|
||||
// ]);
|
||||
// if (empty($deleteCron)) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected function sushiShouldCache()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
$user = ShellApi::exec('whoami');
|
||||
|
||||
$cronList = ShellApi::callBin('cron-jobs-list', [
|
||||
$user,
|
||||
]);
|
||||
|
||||
$rows = [];
|
||||
if (! empty($cronList)) {
|
||||
$cronList = json_decode($cronList, true);
|
||||
if (! empty($cronList)) {
|
||||
foreach ($cronList as $cron) {
|
||||
if (isset($cron['schedule'])) {
|
||||
$rows[] = [
|
||||
'schedule' => $cron['schedule'],
|
||||
'command' => $cron['command'],
|
||||
'user' => $user,
|
||||
'time' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,8 @@ return new class extends Migration
|
|||
$table->id();
|
||||
$table->string('hosting_account_id')->nullable();
|
||||
$table->string('command');
|
||||
$table->string('frequency');
|
||||
$table->string('minute');
|
||||
$table->string('hour');
|
||||
$table->string('day_of_month');
|
||||
$table->string('month');
|
||||
$table->string('day_of_week');
|
||||
$table->string('schedule');
|
||||
$table->string('user');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue