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

Waiting for maintenance mode flag #190

Conversation

ebrahimradi
Copy link
Contributor

@ebrahimradi ebrahimradi commented Apr 6, 2023

@mateusjunges This PR helps to wait for maintenance mode. I guess this is very helpful. what do you think?

Copy link
Owner

@mateusjunges mateusjunges 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 this, but I think it would be better to offer the ability to also run a callback when the consumer detects that the application entered and left maintenance mode. We can define two callbacks that run in this two conditions. Something like this:

if (! app()->isDownForMaintenance()) {
    return;
}

$enteringMaintenanceModeCallback = $this->whenEnterMaintenanceMode;
$enteringMaintenanceModeCallback(...)();

while (app()->isDownForMaintenance()) {
    $sleepTimeInSeconds = random_int(1, 5);
    sleep($sleepTimeInSeconds);
}

$exitingMaintenanceModeCallback = $this->whenExitingMaintenanceMode;
$exitingMaintenanceModeCallback(...)();

@@ -101,6 +101,10 @@ public function consume(): void
}

do {
while (app()->isDownForMaintenance()) {
$sleepTime = rand(1, 5);
Copy link
Owner

Choose a reason for hiding this comment

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

Why a random delay instead of a const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not strong reason! just an example .

@ebrahimradi
Copy link
Contributor Author

I wanted to apply your suggestion,

I findout a better, more generic idea.
instead of ONLY maintenance mode, we can have a series of callbacks that can happen before consuming any message. something like middlewares but not related to messages.
then we can have lifecyle for consumer, before, and after. for now we can ignore after, but we can have before callbacks. what's your idea?

@mateusjunges
Copy link
Owner

Thanks! I have just merged #192 so I'll close this

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.

2 participants