2024-01-01 18:33:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2024-01-02 02:23:29 +00:00
|
|
|
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
|
|
|
|
2024-01-02 02:23:29 +00:00
|
|
|
public function application()
|
2024-01-01 18:33:16 +00:00
|
|
|
{
|
2024-01-02 02:23:29 +00:00
|
|
|
return $this->belongsTo(Application::class);
|
2024-01-01 18:33:16 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-02 02:23:29 +00:00
|
|
|
public function latest_log(): HasOne
|
2024-01-01 18:33:16 +00:00
|
|
|
{
|
2024-01-02 02:23:29 +00:00
|
|
|
return $this->hasOne(ScheduledTaskExecution::class)->latest();
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-02 02:23:29 +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) {
|
2024-08-16 20:05:38 +00:00
|
|
|
if ($this->application->destination && $this->application->destination->server) {
|
|
|
|
|
$server = $this->application->destination->server;
|
2024-09-23 17:51:31 +00:00
|
|
|
|
2024-08-16 20:05:38 +00:00
|
|
|
return $server;
|
|
|
|
|
}
|
2024-08-16 14:01:41 +00:00
|
|
|
} elseif ($this->service) {
|
2024-08-16 20:05:38 +00:00
|
|
|
if ($this->service->destination && $this->service->destination->server) {
|
|
|
|
|
$server = $this->service->destination->server;
|
2024-09-23 17:51:31 +00:00
|
|
|
|
2024-08-16 20:05:38 +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
|
|
|
|
2024-08-16 20:05:38 +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;
|
|
|
|
|
}
|
2024-08-16 20:05:38 +00:00
|
|
|
}
|