I have a model in my custom package
this model has an observer that registered in the package service provider boot method
here is the observer source :
class DedicatedServerObserver
{
/**
* Handle the DedicatedServer "created" event.
*
* @param DedicatedServer $dedicatedServer
* @return void
*/
public function created(DedicatedServer $dedicatedServer)
{
// Create a Virtualizor Connection
$virtualizor = new Virtualizor($dedicatedServer->ip , $dedicatedServer->port , $dedicatedServer->api_key, $dedicatedServer->api_sec);
// Run a Chain of Jobs for Sync Server Data
Bus::chain(
[
new AllowServerTrafficOnCSF($dedicatedServer, $virtualizor),
new SyncIPPools($dedicatedServer, $virtualizor),
new SyncIPs($dedicatedServer,$virtualizor),
new SyncOSTemplates($dedicatedServer, $virtualizor),
new SyncStorages($dedicatedServer, $virtualizor),
new SyncPlans($dedicatedServer, $virtualizor),
new SyncVPSes($dedicatedServer, $virtualizor),
new SetLastSync($dedicatedServer),
]
)->onConnection('database')->onQueue('ip-service')->dispatch();
}
/**
* Handle the DedicatedServer "updated" event.
*
* @param DedicatedServer $dedicatedServer
* @return void
*/
public function updated(DedicatedServer $dedicatedServer)
{
// Create a Virtualizor Connection
$virtualizor = new Virtualizor($dedicatedServer->ip , $dedicatedServer->port , $dedicatedServer->api_key, $dedicatedServer->api_sec);
// Run a Chain of Jobs for Sync Server Data
Bus::chain(
[
new AllowServerTrafficOnCSF($dedicatedServer, $virtualizor),
new SyncIPPools($dedicatedServer, $virtualizor),
new SyncIPs($dedicatedServer,$virtualizor),
new SyncOSTemplates($dedicatedServer, $virtualizor),
new SyncStorages($dedicatedServer, $virtualizor),
new SyncPlans($dedicatedServer, $virtualizor),
new SyncVPSes($dedicatedServer, $virtualizor),
new SetLastSync($dedicatedServer),
]
)->onConnection('database')->onQueue('ip-service')->dispatch();
return;
}
}
Now when I update the model this bus chain runs many times and non-stop and I don't know what the problem is.
the created method runs 1 time and it's okay but the updated method makes a new job every time it runs.