dmitry-ivanov / laravel-console-mutex Goto Github PK
View Code? Open in Web Editor NEWMutex for Laravel Console Commands.
License: MIT License
Mutex for Laravel Console Commands.
License: MIT License
I am using your package to prevent overlapping command that command runs in loop in every second. Code is working fine but getting an error Command is running now! {"exception":"[object] (Illuminated\\Console\\MutexRuntimeException(code: 0): Command is running now! at /vendor/illuminated/console-mutex/src/WithoutOverlapping.php:35)
and this one is full the log file.
How is possible to remove the above error? Please guide
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?
I get this message installing the package.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for illuminated/console-mutex ^5.5 -> satisfiable by illuminated/console-mutex[5.5.0].
- Conclusion: remove laravel/framework v5.4.36
- Conclusion: don't install laravel/framework v5.4.36
- illuminated/console-mutex 5.5.0 requires illuminate/console 5.5.* -> satisfiable by illuminate/console[v5.5.0, v5.5.16, v5.5.17, v5.5.2].
- don't install illuminate/console v5.5.0|don't install laravel/framework v5.4.36
- don't install illuminate/console v5.5.16|don't install laravel/framework v5.4.36
- don't install illuminate/console v5.5.17|don't install laravel/framework v5.4.36
- don't install illuminate/console v5.5.2|don't install laravel/framework v5.4.36
- Installation request for laravel/framework (locked at v5.4.36, required as 5.4.*) -> satisfiable by laravel/framework[v5.4.36].
Installation failed, reverting ./composer.json to its original content.
I tried updating first , same result.
Thanks in advance
When using redis strategy $this->setMutexStrategy('redis'); running a command through console and force stopping, cannot run the command again. It always says that the command is running and never clears.
This does not happen with file strategy.
After force cancel It should behave same as file strategy. Be cleared after some time
Always returns 'Command is running now!' after force stop (CTRL+C).
I installed your package and when using the file mutex option, after the command is finished the mutex file is still there... When I try to rerun the command it will fail with error:
[RuntimeException]
Command is running now!
I used this config setting:
protected $mutexStrategy = 'file';
public function getMutexName()
{
return 'icmutex-test';
}
This is not exactly BUG but I haven't seen the option to open a discussion. Just a minor change to the docs to indicate it works with sqlite
too.
Have been able to use it with sqlite while testing and I've noticed the lock files remain when tests are completed. I'm wondering if they'd have to be cleaned up aftewards?
The issue is similar to what already discussed in #4.
It seems like the internal lock module doesn't work properly on AWS EFS filesystem.
Due to lock file is not deleted laravel-console-mutex
on the next run giving me Command is running now!
exception. Although we are heard the lock file should not be deleted - in that setup the file is present and locking mechanics is broken.
Please, note that we have to update versions for everything, not only
illuminate
packages.
composer.json
according to Laravel's composer.json
.README.md
.master
branch.Everything is working fine when I use the package in real conditions.
However, I can't make tests on commands that are implementing the WithoutOverlapping
trait: the first test is OK but all other tests are throwing the Illuminated\Console\MutexRuntimeException: Command is running now!
error.
I verified by adding a dd('test')
in the releaseMutexLock
from the NinjaMutex\Lock\FlockLock
(default file strategy is set with no timeout) and 4 tests are executed before the mutex is released.
Is there a way to force the mutex to be released after each test ?
Implement a command and write several tests in a same test class, the mutex will not be released between each test.
The mutex should be released right after the command has finished.
The mutex is not released right after the command has finished.
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!
Can you support laravel 5.8 for this package?
The port setup in the Laravel database config file isn't added to the arguments for NinjaMutex\Lock\MySqlLock
. I've created a pull request where I've added the port: #1
Laravel 5.7 was released a couple of days ago...
Please, note that we have to update versions for everything, not only
illuminate
packages.
composer.json
according to Laravel's composer.json
.README.md
.master
branch.Package Version: 7.0.0
PHP Version: 7.4
if you want to run a command in test more than 1 time you get an error than the command is running now
<?php
class YourCommandTest extends TestCase
{
public function testExample()
{
$this->artisan('command', ['param' => 'value']);
}
public function test2Example()
{
$this->artisan('command', ['param' => 'value']); // throw exception
}
}
Hi, nice package.
Am deploying my system on an ubuntu 16.04 server and sometimes the lock fails to release and thus all my tasks just hung like forever and the lock is never released.
What cloud be the problem.
Am using mysql strategy.
template of my code below:
namespace App\Console\Commands;
use App\Helpers\Constants;
use App\Jobs\SendBulkSms;
use App\Models\Sms;
use Illuminate\Console\Command;
use Illuminated\Console\WithoutOverlapping;
class QueueBulkSms extends Command
{
use WithoutOverlapping;
protected $mutexStrategy = 'mysql';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bongatech:queueSms';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Queue Sms for sending';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->line("Fetching sms for queue");
try {
Sms::where('status', Constants::AWAITING_QUEUE)->chunk(500, function ($messages){
foreach ($messages as $message){
SendBulkSms::dispatch($message->short_message, $message->msisdn, $message->sender_id, $message->id)->onQueue('send_sms');
$message->update(['status'=>Constants::QUEUED]);
}
});
}
catch (\Throwable $throwable){
}
}
}
Laravel 6 is released today!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.