dmitry-ivanov/laravel-console-mutex

Suppress RuntimeException?

francoism90 opened this issue ยท 3 comments

To prevent overlapping I'm using your package that basically runs a command in a loop.
This is all working fine, only the log is being flood with RuntimeException(code: 0): Command is running now!... Is it possible to log a (debug) message instead of a full exception? Do you maybe have a better idea? :)

Thanks for your package!

First of all - thank you for your kind words! ๐Ÿ™‚

According to your situation, here is what I think:

  • Maybe you could run your console command not in the loop, but via Laravel Scheduler, for example by using everyMinute() method? That way, you'll still have protection from overlapping, but these situations would become rare events, which potentially require some actions.

  • You can use Laravel Console Logger to separate log files of your console commands from the main Laravel log file(s).

  • You can handle RuntimeException('Command is running now!') in the App\Exceptions\Handler class and basically provide any custom logic you want. Something like that:

if ($this->isConsoleMutexException($exception)) {
    // Any custom logic here...
}

// ...

protected function isConsoleMutexException(Exception $exception)
{
    return ($exception instanceof RuntimeException)
        && ($exception->getMessage() == 'Command is running now!');
}

I hope it helps! ๐Ÿ™‚

@dmitry-ivanov Many thanks! Added this in report() yesterday and it doesn't log anymore.

Keep up the good work.

@francoism90 Hey, hope you're doing great! ๐Ÿ™‚

Just wanted to let you know that I've added the MutexRuntimeException class to make checks easier.

You'd be able to simplify your check to:

use Illuminated\Console\MutexRuntimeException;

protected function isConsoleMutexException(Exception $exception)
{
    return $exception instanceof MutexRuntimeException;
}

PS: I've already pushed it to master, and it would be a part of the 6.0.0 release soon.