coolify/app/Models/ScheduledTask.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2024-01-01 18:33:16 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
2024-01-01 18:33:16 +00:00
class ScheduledTask extends BaseModel
{
protected $guarded = [];
public function service()
{
return $this->belongsTo(Service::class);
}
2024-06-10 20:43:34 +00:00
public function application()
2024-01-01 18:33:16 +00:00
{
return $this->belongsTo(Application::class);
2024-01-01 18:33:16 +00:00
}
2024-06-10 20:43:34 +00:00
public function latest_log(): HasOne
2024-01-01 18:33:16 +00:00
{
return $this->hasOne(ScheduledTaskExecution::class)->latest();
}
2024-06-10 20:43:34 +00:00
public function executions(): HasMany
{
2024-09-03 15:35:18 +00:00
// Last execution first
2024-08-21 14:53:53 +00:00
return $this->hasMany(ScheduledTaskExecution::class)->orderBy('created_at', 'desc');
2024-01-01 18:33:16 +00:00
}
2024-08-16 14:01:41 +00:00
public function server()
{
if ($this->application) {
if ($this->application->destination && $this->application->destination->server) {
$server = $this->application->destination->server;
2024-09-23 17:51:31 +00:00
return $server;
}
2024-08-16 14:01:41 +00:00
} elseif ($this->service) {
if ($this->service->destination && $this->service->destination->server) {
$server = $this->service->destination->server;
2024-09-23 17:51:31 +00:00
return $server;
}
} elseif ($this->database) {
if ($this->database->destination && $this->database->destination->server) {
$server = $this->database->destination->server;
2024-09-23 17:51:31 +00:00
return $server;
}
2024-08-16 14:01:41 +00:00
}
2024-09-23 17:51:31 +00:00
2024-08-16 14:01:41 +00:00
return null;
}
}