jdavidbakr / MultiServerEvent

Laravel plugin to allow scheduled events across multiple servers with the same scheduler to not overlap.
MIT License
37 stars 17 forks source link

Method withoutOverlappingMultiServer does not exist on Laravel 5.5.20 #18

Closed johntiror closed 6 years ago

johntiror commented 6 years ago

Hi, I'm on Laravel 5.5.20. I followed the readme but I'm getting the error "Method withoutOverlappingMultiServer does not exist.". Here my code:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \jdavidbakr\MultiServerEvent\Commands\MultiServerMigrationService::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @return void
     */
    protected function defineConsoleSchedule()
    {
        $this->app->instance(
            Schedule::class,
            $schedule = new \jdavidbakr\MultiServerEvent\Scheduling\Schedule()
        );

        $this->schedule($schedule);
    }

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function (){
            Log::debug("test");
        })->everyMinute()->withoutOverlappingMultiServer();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

Any idea what I'm doing wrong?

thanks

jdavidbakr commented 6 years ago

What version of Laravel are you using?

Try adding a dd(__FILE__) call in the beginning of the defineConsoleSchedule() function to ensure that it's running. It should get hit every time you just call php artisan. That will tell you at least if the new scheduler is being registered.

jdavidbakr commented 6 years ago

I just saw that your Laravel version is in the issue title. I'm using it in a 5.5.23 project so I know that it's still working with the latest Laravel. Try what I said above to ensure that the console schedule is being injected properly.

johntiror commented 6 years ago

It's running:

root@123:/var/www/html/app# php artisan schedule:run
"/var/www/html/soleranabot/app/Console/Kernel.php"

But still:

root@123:/var/www/html/app# php artisan schedule:run

  [BadMethodCallException]                              
  Method withoutOverlappingMultiServer does not exist.  
jdavidbakr commented 6 years ago

use $schedule->command() not $schedule->call() - this package won't work with a callback.

johntiror commented 6 years ago

Thanks, do you know how can I run my custom code inside a command()? I can't find any reference, it seems command() is only used for artisan commands. Thanks