Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Document the pending tenants feature and the related commands #225

Open
lukinovec opened this issue Nov 28, 2022 · 3 comments
Open

Comments

@lukinovec
Copy link
Collaborator


title: Pending tenants
extends: _layouts.documentation
section: content

Pending tenants {#pending-tenants}

Too many tenant migrations can make creating new tenants very slow. To solve that, you can create ready to use pending tenants.

Pending tenants are tenants whose pending_since attribute is not null. Instead of creating new tenants, you can pull a pending tenant from the pending tenant pool (make them non-pending).

Pending tenants exclusion from queries

Pending tenants can get included or excluded from Tenant queries (e.g. Tenant::all()) depending on the value of the tenancy.pending.include_in_queries config key. To exclude the tenants from a query manually, add ->withoutPending() to the query, e.g. Tenant::where(...)->withoutPending() and to include them, add ->withPending() instead.

Note: See the HasPending and PendingScope traits to learn more about the available methods.

Creating pending tenants

To create pending tenants, you can use the tenants:pending-create command, or the CreatePendingTenants job. By default, these create pending tenants until the maximum count (the pool size) is reached. The pool size can be changed using the 'tenancy.pending.count' config key. You can also use the Tenant::createPending() method defined in the HasPending trait.

Deleting pending tenants

To clear the pending tenant pool, you can use the tenants:pending-clear command, or the ClearPendingTenants job.

Note: Learn more about the commands on [the console commands page in the docs]({{ $page->link('console-commands') }}).


// CONSOLE COMMANDS PAGE

Tenant-aware commands and pending tenants

Tenant-aware commands respect your tenancy.pending.include_in_queries configuration. The commands also have the --with-pending option which makes the command run for pending tenants too. For example, tenants:migrate --with-pending runs tenants:migrate for the pending tenants too, even if the tenancy.pending.include_in_queries config is false.

Create pending tenants

The tenants:pending-create command creates pending tenants either until the pending tenant pool is full. You can specify how many pending tenants will be created by passing the count in the --count option.

php artisan tenants:pending-create --count=10
10 pending tenants created.
10 pending tenants ready to be used.

Clear pending tenants

The tenants:pending-clear command deletes all pending tenants. Passing the --older-than-days or the --older-than-hours option makes the command delete only the tenants that exist for more days/hours than the day/hour amount passed in the option. These two options can't be used simultaneously.

php artisan tenants:pending-clear --older-than-days=2
Removing pending tenants.
10 pending tenants deleted.
@lukinovec lukinovec changed the title Document the pending tenants feature [4.x] Document the pending tenants feature and the related commands Nov 28, 2022
@stancl
Copy link
Owner

stancl commented Feb 20, 2023

Adding a note to mention casting maintenace_mode to an array in the Tenant model https://discord.com/channels/976506366502006874/1043694788358189167/1077246349428396042

@lukinovec
Copy link
Collaborator Author

lukinovec commented Feb 23, 2023

Thanks for the note @stancl, I mentioned that in the related issue

@stancl
Copy link
Owner

stancl commented Feb 23, 2023

Ah nevermind, I opened the wrong thread here. It does belong to #214 yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants