GithubHelp home page GithubHelp logo

dmitry-ivanov / laravel-console-mutex Goto Github PK

View Code? Open in Web Editor NEW
137.0 137.0 26.0 2.26 MB

Mutex for Laravel Console Commands.

License: MIT License

PHP 100.00%
command console laravel laravel-package locker mutex mutex-lock no-overlapping semaphore

laravel-console-mutex's Introduction

Hi, I'm Dmitry Ivanov! Nice to meet you! I'm a Software Engineer, Laravel Developer, Open-Source Developer, Problem Solver, and Constant Learner.

laravel-console-mutex's People

Contributors

dmirogin avatar dmitry-ivanov avatar mihan007 avatar rafacouto avatar sbladam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-console-mutex's Issues

Error 'Command is running now'

Versions:

  • Package Version: 8.28
  • PHP Version: 8.0

Description:

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

Command with different params is not working

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?

Instalation conflict.

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

Mutex redis always throws 'Command is running now!' after force stop

Versions:

  • Package Version: 5.8.*
  • PHP Version: 7.4.3
  • Redis package "predis/predis": "^1.1"

Description:

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.

Expected:

After force cancel It should behave same as file strategy. Be cleared after some time

Actual:

Always returns 'Command is running now!' after force stop (CTRL+C).

Mutex file is not deleted

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';
}

Lock files remain in storage

Versions:

  • Package Version: #.#.#
  • PHP Version: #.#.# 8.1.2

Description:

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?

Evidence

confirm_mutex_works

dynamic_strategy_based_on_env

not_deleted_when_done

file lock mechanics doesn't work on EFS backed filesystem

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.

Laravel 8

Follow these steps:

Please, note that we have to update versions for everything, not only illuminate packages.

  1. Update versions in composer.json according to Laravel's composer.json.
  2. Add the newly supported version to README.md.
  3. Open PR to the master branch.

Issue with PHPUnit testing and mutex not released

Versions:

  • Package Version: 8.1.0
  • PHP Version: 8.0

Description:

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 ?

Steps to reproduce:

Implement a command and write several tests in a same test class, the mutex will not be released between each test.

Expected:

The mutex should be released right after the command has finished.

Actual:

The mutex is not released right after the command has finished.

Suppress RuntimeException?

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!

Laravel 10.x support

Follow these steps:

Please, note that we have to update versions for everything, not only illuminate packages.

  1. Update versions in composer.json according to Laravel's composer.json.
  2. Add the newly supported version to README.md.
  3. Open PR to the master branch.

Not working in tests

Versions:

  • Package Version: 7.0.0

  • PHP Version: 7.4

Description:

if you want to run a command in test more than 1 time you get an error than the command is running now

Steps to reproduce:

<?php
class YourCommandTest extends TestCase
{

    public function testExample()
    {
        $this->artisan('command', ['param' => 'value']);
    }

    public function test2Example()
    {
        $this->artisan('command', ['param' => 'value']); // throw exception
    }
}

Lock fails to release

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){

        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.