mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
[2.1.0] Fix queue race conditions (#178)
* Add TenantDoesNotExist exception, fix queued migrator serialization * wip * Apply fixes from StyleCI * Use only one config for queueing * Apply fixes from StyleCI * rename test * rename test
This commit is contained in:
parent
e98db460ec
commit
3e78410d8a
8 changed files with 78 additions and 28 deletions
|
|
@ -62,18 +62,24 @@ class TenantManager
|
|||
$this->ensureTenantCanBeCreated($tenant);
|
||||
|
||||
$this->storage->createTenant($tenant);
|
||||
$this->database->createDatabase($tenant);
|
||||
|
||||
/** @var \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating */
|
||||
$afterCreating = [];
|
||||
|
||||
if ($this->shouldMigrateAfterCreation()) {
|
||||
if ($this->shouldQueueMigration()) {
|
||||
QueuedTenantDatabaseMigrator::dispatch($tenant);
|
||||
} else {
|
||||
$this->artisan->call('tenants:migrate', [
|
||||
'--tenants' => [$tenant['id']],
|
||||
]);
|
||||
}
|
||||
$afterCreating += $this->databaseCreationQueued() ? [
|
||||
new QueuedTenantDatabaseMigrator($tenant),
|
||||
] : [
|
||||
function () use ($tenant) {
|
||||
$this->artisan->call('tenants:migrate', [
|
||||
'--tenants' => [$tenant['id']],
|
||||
]);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
$this->database->createDatabase($tenant, $afterCreating);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -315,9 +321,9 @@ class TenantManager
|
|||
return $this->app['config']['tenancy.migrate_after_creation'] ?? false;
|
||||
}
|
||||
|
||||
public function shouldQueueMigration(): bool
|
||||
public function databaseCreationQueued(): bool
|
||||
{
|
||||
return $this->app['config']['tenancy.queue_automatic_migration'] ?? false;
|
||||
return $this->app['config']['tenancy.queue_database_creation'] ?? false;
|
||||
}
|
||||
|
||||
public function shouldDeleteDatabase(): bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue