mirror of
https://github.com/cupcakearmy/coolify.git
synced 2024-10-22 08:04:19 +02:00
feat: Update auto update and update check frequencies in settings
This commit is contained in:
parent
d3085e1ade
commit
5a82395bb7
@ -76,11 +76,11 @@ private function schedule_updates($schedule)
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
|
||||
$updateCheckFrequency = $settings->update_check_frequency ?? '0 0 * * *';
|
||||
$updateCheckFrequency = $settings->update_check_frequency;
|
||||
$schedule->job(new CheckForUpdatesJob)->cron($updateCheckFrequency)->onOneServer();
|
||||
|
||||
if ($settings->is_auto_update_enabled) {
|
||||
$autoUpdateFrequency = $settings->auto_update_frequency ?? '0 11,23 * * *';
|
||||
$autoUpdateFrequency = $settings->auto_update_frequency;
|
||||
$schedule->job(new UpdateCoolifyJob)->cron($autoUpdateFrequency)->onOneServer();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
use App\Jobs\CheckForUpdatesJob;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Server;
|
||||
use Cron\CronExpression;
|
||||
use Livewire\Component;
|
||||
|
||||
class Index extends Component
|
||||
@ -39,8 +38,8 @@ class Index extends Component
|
||||
'settings.instance_name' => 'nullable',
|
||||
'settings.allowed_ips' => 'nullable',
|
||||
'settings.is_auto_update_enabled' => 'boolean',
|
||||
'auto_update_frequency' => 'nullable|string',
|
||||
'update_check_frequency' => 'nullable|string',
|
||||
'auto_update_frequency' => 'string',
|
||||
'update_check_frequency' => 'string',
|
||||
];
|
||||
|
||||
protected $validationAttributes = [
|
||||
@ -97,14 +96,20 @@ public function submit()
|
||||
}
|
||||
$this->validate();
|
||||
|
||||
if ($this->is_auto_update_enabled && ! $this->validateCronExpression($this->auto_update_frequency)) {
|
||||
if ($this->is_auto_update_enabled && ! validate_cron_expression($this->auto_update_frequency)) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
|
||||
if (empty($this->auto_update_frequency)) {
|
||||
$this->auto_update_frequency = '0 0 * * *';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->validateCronExpression($this->update_check_frequency)) {
|
||||
if (! validate_cron_expression($this->update_check_frequency)) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
|
||||
if (empty($this->update_check_frequency)) {
|
||||
$this->update_check_frequency = '0 * * * *';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -149,40 +154,6 @@ public function submit()
|
||||
}
|
||||
}
|
||||
|
||||
private function validateCronExpression($expression): bool
|
||||
{
|
||||
if (empty($expression)) {
|
||||
return true;
|
||||
}
|
||||
$isValid = false;
|
||||
try {
|
||||
$cronExpression = new CronExpression($expression);
|
||||
$isValid = $cronExpression->getNextRunDate() !== false;
|
||||
} catch (\Exception $e) {
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if (isset(VALID_CRON_STRINGS[$expression])) {
|
||||
$isValid = true;
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
public function updatedAutoUpdateFrequency()
|
||||
{
|
||||
if (! $this->validateCronExpression($this->auto_update_frequency)) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
|
||||
}
|
||||
}
|
||||
|
||||
public function updatedUpdateCheckFrequency()
|
||||
{
|
||||
if (! $this->validateCronExpression($this->update_check_frequency)) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkManually()
|
||||
{
|
||||
CheckForUpdatesJob::dispatchSync();
|
||||
|
@ -12,8 +12,8 @@
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('instance_settings', function (Blueprint $table) {
|
||||
$table->string('auto_update_frequency')->default('0 0 * * *')->nullable();
|
||||
$table->string('update_check_frequency')->default('0 * * * *')->nullable();
|
||||
$table->string('auto_update_frequency')->default('0 0 * * *');
|
||||
$table->string('update_check_frequency')->default('0 * * * *');
|
||||
$table->boolean('new_version_available')->default(false);
|
||||
});
|
||||
}
|
||||
|
@ -39,34 +39,36 @@
|
||||
<x-forms.input id="settings.allowed_ips" label="Allowed IPs"
|
||||
helper="Allowed IP lists for the API. A comma separated list of IPs. Empty means you allow from everywhere."
|
||||
placeholder="1.1.1.1,8.8.8.8" />
|
||||
|
||||
<h4 class="pt-6">Advanced</h4>
|
||||
<div class="text-right md:w-96">
|
||||
<x-forms.checkbox instantSave id="is_registration_enabled" label="Registration Allowed" />
|
||||
<x-forms.checkbox instantSave id="do_not_track" label="Do Not Track" />
|
||||
</div>
|
||||
<h5 class="pt-4 font-bold text-white">Update</h5>
|
||||
<div class="text-right md:w-96">
|
||||
@if (!is_null(env('AUTOUPDATE', null)))
|
||||
<div class="text-right md:w-96">
|
||||
<x-forms.checkbox instantSave helper="AUTOUPDATE is set in .env file, you need to modify it there."
|
||||
disabled id="is_auto_update_enabled" label="Enabled" />
|
||||
</div>
|
||||
@else
|
||||
<x-forms.checkbox instantSave id="is_auto_update_enabled" label="Auto Update Enabled" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex items-end gap-2">
|
||||
<x-forms.input required id="update_check_frequency" label="Update Check Frequency"
|
||||
placeholder="0 * * * *"
|
||||
helper="Cron expression for update check frequency (check for new Coolify versions and pull new Service Templates from CDN). Default is every hour." />
|
||||
<x-forms.button wire:click='checkManually'>Check Manually</x-forms.button>
|
||||
</div>
|
||||
|
||||
@if (is_null(env('AUTOUPDATE', null)) && $is_auto_update_enabled)
|
||||
<x-forms.input required id="auto_update_frequency" label="Auto Update Frequency" placeholder="0 0 * * *"
|
||||
helper="Cron expression for auto update frequency (automatically update coolify). Default is every day at 00:00" />
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h4 class="pt-6">Advanced</h4>
|
||||
<div class="text-right md:w-96">
|
||||
<x-forms.checkbox instantSave id="is_registration_enabled" label="Registration Allowed" />
|
||||
<x-forms.checkbox instantSave id="do_not_track" label="Do Not Track" />
|
||||
</div>
|
||||
<h5 class="pt-4 font-bold text-white">Update</h5>
|
||||
<div class="text-right md:w-96">
|
||||
@if (!is_null(env('AUTOUPDATE', null)))
|
||||
<div class="text-right md:w-96">
|
||||
<x-forms.checkbox instantSave helper="AUTOUPDATE is set in .env file, you need to modify it there."
|
||||
disabled id="is_auto_update_enabled" label="Enabled" />
|
||||
</div>
|
||||
@else
|
||||
<x-forms.checkbox instantSave id="is_auto_update_enabled" label="Auto Update Enabled" />
|
||||
@endif
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex items-end gap-2">
|
||||
<x-forms.input id="update_check_frequency" label="Update Check Frequency" placeholder="0 * * * *"
|
||||
helper="Cron expression for update check frequency (check for new Coolify versions and pull new Service Templates from CDN). Default is every hour." />
|
||||
<x-forms.button wire:click='checkManually'>Check Manually</x-forms.button>
|
||||
</div>
|
||||
|
||||
@if (is_null(env('AUTOUPDATE', null)) && $is_auto_update_enabled)
|
||||
<x-forms.input id="auto_update_frequency" label="Auto Update Frequency" placeholder="0 0 * * *"
|
||||
helper="Cron expression for auto update frequency (automatically update coolify). Default is every day at 00:00" />
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user