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

[9.x] Move maintenance mode logic #40070

Merged
merged 27 commits into from
Dec 17, 2021
Merged

[9.x] Move maintenance mode logic #40070

merged 27 commits into from
Dec 17, 2021

Conversation

wimulkeman
Copy link
Contributor

@wimulkeman wimulkeman commented Dec 16, 2021

Moving the maintenance mode logic to its own class. This enables users to extend/overwrite the class with their own logic.

Overwriting the logic may be needed if for example the application is run on multiple servers. In this case the developer would want to extend the storage logic for the maintenance mode to implement a solution that can change the maintenance state for all the servers at once and reverse the maintenance mode with one command.

By separating the maintenance mode logic the framework opens the door for packages that could handle the maintenance mode through different mechanisms like using the cache (as proposed in a blog https://www.raypold.com/posts/laravel-distributed-maintenance-mode/).

The need for this was shown within the discussions laravel/ideas#1944 and #36474.

This PR is a follow-up to the PR #40059 with suggested changes and pointed to the master instead of the 8.x branch because it contains backward incompatible changes.

Wim Ulkeman added 7 commits December 16, 2021 09:34
Moving the maintenance mode logic to its own class. This enables users to extend/overwrite the class with their own logic.

Overwriting the logic may be needed if for example the application is running on multiple servers.

Fixes #36474
Adding the isUp method to check if the application is up or is down for maintenance.

Relates to #36474
Extend the documentation about what the code does. Also use FQN.

Relates to #36474
Use the make method instead of the app function to retrieve an instance of the MaintenanceMode container.

Relates to #36474
Update the docblock with the newly added method param.

Relates to #36474
Update the docblock with the newly added method param.

Relates to #36474
Wim Ulkeman added 5 commits December 16, 2021 10:26
Updating documentation style to comply to the style used within the Laravel codebase.
Updating documentation style to comply to the style used within the Laravel codebase.
Move the class from its own namespace to the Foundation namespace.

Relates to #36474
Updating documentation style to comply to the style used within the Laravel codebase.
Updating documentation style to comply to the style used within the Laravel codebase.
@driesvints driesvints changed the title Move maintenance mode logic [9.x] Move maintenance mode logic Dec 16, 2021
wimulkeman and others added 3 commits December 16, 2021 11:05
…gMaintenance.php

Co-authored-by: Dries Vints <dries@vints.io>
…gMaintenance.php

Co-authored-by: Dries Vints <dries@vints.io>
Create an application methode to retrieve the MaintenanceMode instance. This method reduces the need to fetch the MaintenanceMode with the usage of an additional argument in the middleware.

Relates to #36474
src/Illuminate/Foundation/Console/DownCommand.php Outdated Show resolved Hide resolved
src/Illuminate/Foundation/Console/DownCommand.php Outdated Show resolved Hide resolved
src/Illuminate/Foundation/Console/UpCommand.php Outdated Show resolved Hide resolved
src/Illuminate/Foundation/Console/UpCommand.php Outdated Show resolved Hide resolved
Wim Ulkeman added 2 commits December 16, 2021 11:28
Adding documentation for the newly added methods.

Relates to #36474
Use the application method instead of using autowiring. The application method provides the MaintenanceMode instance which removes the requirement to inject the class in the handler method.

Relates to #36474
@wimulkeman
Copy link
Contributor Author

Because of the changes made the PR no longer introduces new method arguments to existing code. Should this PR shill be pointed at master (9.x) or instead to the 8.x branch?

src/Illuminate/Foundation/MaintenanceMode.php Outdated Show resolved Hide resolved
src/Illuminate/Foundation/MaintenanceMode.php Outdated Show resolved Hide resolved
Co-authored-by: Dries Vints <dries@vints.io>
@driesvints
Copy link
Member

driesvints commented Dec 16, 2021

Because of the changes made the PR no longer introduces new method arguments to existing code. Should this PR shill be pointed at master (9.x) or instead to the 8.x branch?

@wimulkeman you're totally correct. Feel free to re-send this to 8.x, thanks! Good job on the PR so far 👍

One thing that can very much help this PR get merged is explain the use case a bit more thoroughly in your PR description. So state clearly why this is needed (multiple servers but also different stores).

Thanks!

Co-authored-by: Dries Vints <dries@vints.io>
@seriquynh
Copy link
Contributor

This PR no longer introduces new method arguments to existing code but it adds a new method into Application contract. So, it's still a breaking-change PR and should be sent to 9.x.

Remove the comparison with the false value. The method always returns a bool which only allows a true or false return value. This make the comparison redundant.

Relates to #36474
Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the PR. I'd maybe even make some proxy methods on Application for isUp, isDown, up and down to make the code even cleaner but let's see what @taylorotwell says.

Remove the unused import. Because the FQN is used in the DocBlock the import has become redundant.
@ziadoz
Copy link
Contributor

ziadoz commented Dec 16, 2021

This looks like a really useful feature. Would it be worth adding a contract/interface for the MaintenanceMode class itself?

Wim Ulkeman added 2 commits December 16, 2021 16:58
Add an interface under the contracts to enable developers to easily extend the MaintenanceMode class.
Updating documentation style to comply to the style used within the Laravel codebase.
@wimulkeman
Copy link
Contributor Author

Agreed I think it would benefit from a contract. The contract would make it easier for developers to overwrite the original class with their own logic.

Wim Ulkeman added 2 commits December 17, 2021 10:23
Bind the default MaintenanceMode class to the contract reference in the service container.

This enables users to set-up their own contract binding to overwrite the default Maintenance Mode behavior.
Updating documentation style to comply to the style used within the Laravel codebase.
wimulkeman and others added 2 commits December 17, 2021 10:57
Co-authored-by: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com>
@taylorotwell
Copy link
Member

Can you allow me to push to this branch so I can update the PR? Allow edits from maintainers.

@wimulkeman
Copy link
Contributor Author

wimulkeman commented Dec 17, 2021

@taylorotwell I've given you permission to the repository. I couldn't find the setting on this PR page, so I gave you the needed permissions on the forked repo instead. Is that workable?

I am missing the option because the fork was created under an organisation. If needed I could move it to my own account and recreate the pull request so I can allow the option.

@taylorotwell taylorotwell merged commit dc47126 into laravel:master Dec 17, 2021
@taylorotwell taylorotwell deleted the #36474-enable_overwriting_maintenance_methods branch December 17, 2021 19:52
@taylorotwell
Copy link
Member

Thanks for contributing to Laravel! ❤️

@driesvints
Copy link
Member

Thanks for your PR @wimulkeman 👍

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

Successfully merging this pull request may close these issues.

6 participants