mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 11:20:53 +08:00
feat: introduce WebSocket sync for XBoard nodes
- Implement Workerman-based `xboard:ws-server` for real-time node synchronization. - Support custom routes, outbounds, and certificate configurations via JSON. - Optimize scheduled tasks with `lazyById` to minimize memory footprint. - Enhance reactivity using Observers for `Plan`, `Server`, and `ServerRoute`. - Expand protocol support for `httpupgrade`, `h2`, and `mieru`.
This commit is contained in:
45
app/Jobs/NodeUserSyncJob.php
Normal file
45
app/Jobs/NodeUserSyncJob.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\NodeSyncService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NodeUserSyncJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $tries = 2;
|
||||
public $timeout = 10;
|
||||
|
||||
public function __construct(
|
||||
private readonly int $userId,
|
||||
private readonly string $action,
|
||||
private readonly ?int $oldGroupId = null
|
||||
) {
|
||||
$this->onQueue('notification');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$user = User::find($this->userId);
|
||||
|
||||
if ($this->action === 'updated' || $this->action === 'created') {
|
||||
if ($this->oldGroupId) {
|
||||
NodeSyncService::notifyUserRemovedFromGroup($this->userId, $this->oldGroupId);
|
||||
}
|
||||
if ($user) {
|
||||
NodeSyncService::notifyUserChanged($user);
|
||||
}
|
||||
} elseif ($this->action === 'deleted') {
|
||||
if ($this->oldGroupId) {
|
||||
NodeSyncService::notifyUserRemovedFromGroup($this->userId, $this->oldGroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user