Added system polling
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -283,7 +282,7 @@ class Address extends Model
|
||||
return NULL;
|
||||
|
||||
default:
|
||||
throw new \Exception('Unknown role: '.serialize($this->role));
|
||||
throw new \Exception(sprintf('Unknown role: %s (%d)',serialize($this->role),$this->id));
|
||||
}
|
||||
|
||||
return $parent?->parent();
|
||||
|
69
app/Models/Job.php
Normal file
69
app/Models/Job.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class Job extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $casts = [
|
||||
'payload' => 'array',
|
||||
'reserved_at' => 'datetime',
|
||||
'available_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
$this->table = Config::get('queue.connections.' . (Config::get('queue.default', 'database')) . '.table', 'jobs');
|
||||
}
|
||||
|
||||
public function getDisplayNameAttribute()
|
||||
{
|
||||
return $this->payload['displayName'];
|
||||
}
|
||||
|
||||
public function getMaxTriesAttribute()
|
||||
{
|
||||
return $this->payload['maxTries'];
|
||||
}
|
||||
|
||||
public function getDelayAttribute()
|
||||
{
|
||||
return $this->payload['delay'];
|
||||
}
|
||||
|
||||
public function getUUIDAttribute()
|
||||
{
|
||||
return $this->payload['uuid'];
|
||||
}
|
||||
|
||||
public function getTimeoutAttribute()
|
||||
{
|
||||
return $this->payload['timeout'];
|
||||
}
|
||||
|
||||
public function getRetryUntilAttribute()
|
||||
{
|
||||
return !is_null($this->payload['retryUntil']) ? new \Carbon\Carbon($this->payload['retryUntil']) : null;
|
||||
}
|
||||
|
||||
public function getTimeoutAtAttribute()
|
||||
{
|
||||
return !is_null($this->payload['timeout_at']) ? new \Carbon\Carbon($this->payload['timeout_at']) : null;
|
||||
}
|
||||
|
||||
public function getCommandNameAttribute()
|
||||
{
|
||||
return $this->payload['data']['commandName'];
|
||||
}
|
||||
|
||||
public function getCommandAttribute()
|
||||
{
|
||||
return unserialize($this->payload['data']['command']);
|
||||
}
|
||||
}
|
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Jobs\AddressPoll;
|
||||
|
||||
class System extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
@@ -214,4 +216,13 @@ class System extends Model
|
||||
return ($item->role & $type) && ($myzones->search($item->zone_id) !== FALSE);
|
||||
});
|
||||
}
|
||||
|
||||
public function poll(): ?Job
|
||||
{
|
||||
return Job::where('queue',AddressPoll::QUEUE)
|
||||
->get()
|
||||
->where(function($item) {
|
||||
return $this->akas->pluck('id')->search($item->command->address->id) !== FALSE; })
|
||||
->last();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user