Skip to content

Command with different params is not working #22

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

Closed
moazam1 opened this issue Nov 5, 2020 · 5 comments
Closed

Command with different params is not working #22

moazam1 opened this issue Nov 5, 2020 · 5 comments

Comments

@moazam1
Copy link

moazam1 commented Nov 5, 2020

Hi,

First of all great work. For some reasons Laravel's withoutOverlapping() method didn't work for me because I was seeing same commands overlapping so I opt in to use your package. I think Laravel team should use your package!

I have a command which accepts different arguments i.e. php artisan --action=cleanup or php artisan --action=check-db --table=xyz

Both commands are doing different nature of tasks so your package shouldn't throw error. Is there any chance you can add lock based on the params passed to command?

Also, it would be great if you can add an option to show a warning message instead of throwing exception: Command is running now! A variable like this in the class will work fine $this->useWarning = true; or have a setting?

@dmitry-ivanov
Copy link
Owner

Hi @moazam1,

Thank you for your kind words! 🙏

There are two different concepts for artisan console commands - arguments and options.
(These are actually options in your example, not arguments)

By default, Laravel Console Mutex takes into account only arguments when it generates the mutex name. But you can easily change that behavior by overriding the getMutexName() method (see readme for the related example).

PS:

Also, it would be great if you can add an option to show a warning message instead of throwing exception: Command is running now! A variable like this in the class will work fine $this->useWarning = true; or have a setting?

To be honest, that part of the package has changed several times. Initially, it was simply an info message with exit(), then I've used setCode() method to override the command's body, then switched to throwing an exception. And I've found that the exception works best because it stops the execution immediately without affecting other integrations that the given artisan console command might have (we check for the mutex in the initialize() method of the console command, which could also be used by other integrations). Also, if you're using the Laravel Console Logger - it would be captured in logs for you automatically (you can even get the email notification if you want). Anyways, the package throws a custom exception (Illuminated\Console\MutexRuntimeException), so you can always change the way it's handled in your exception handler class.

I hope it helps! 👍

@moazam1
Copy link
Author

moazam1 commented Nov 12, 2020

@dmitry-ivanov thank you for the message. I am using Lumen 5.5.x. Due to package dependencies I can't upgrade my Lumen version to see MutexRuntimeException. Right now I am getting RuntimeException. Do you have any suggestion how to prevent this exception? I don't want to put it in the ignore list.

@dmitry-ivanov
Copy link
Owner

@moazam1 I've released 5.5.6 for you, and now it throws custom Illuminated\Console\MutexRuntimeException on 5.5 as well 👍

@moazam1
Copy link
Author

moazam1 commented Nov 12, 2020

Thank you so much!

@dmitry-ivanov
Copy link
Owner

You're welcome! 👍

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