gecche / laravel-multidomain

A Laravel extension for using a laravel application on a multi domain setting
MIT License
843 stars 105 forks source link

I think it's a schedule --domain dispatch bug. #54

Closed jskorlol closed 3 years ago

jskorlol commented 3 years ago
* * * * * root php -d memory_limit=-1 /var/www/artisan schedule:run --domain=api.domain.com >/tmp/cron.last 2>&1

php /var/www/artisan queue:work --domain=api.domain.com --timeout=1800 --sleep=3 --tries=1

I run cron as an option,

$schedule->command('cleanPdfs', ['--thread'=>'queue'])->everyMinute()->timezone('Asia/Seoul');

The schedule reads like this:

    protected $signature = 'cleanPdfs {--thread=single}';

    protected $description = 'Command description';

    public function handle()
    {
         dispatch((new APICallCommandJob("sub1.domain.com", $command)));
    }

When the command in the schedule is executed like this, Dispatch is normally registered in Job.

However, at the same time as dispatch job registration, Like dispatch_now too run, and dispatch is too run

That is, once in the queue, once in the schedule php, a total of 2 runs.

to solve this

I should have used the env option in cron, not the domain option.

* * * * * root php -d memory_limit=-1 /var/www/artisan schedule:run --env=api.domain.com >/tmp/cron.last 2>&1
$schedule->command('cleanPdfs', ['--thread'=>'queue'])->everyMinute()->timezone('Asia/Seoul')->environments('api.domain.com');

I'm not sure where the problem is either, sorry.

gecche commented 3 years ago

Hi,

I'm currently off until Thursday so I can't check your problem right now. However, honestly, I didn't understand what do you mean :) The only thing I can say, seeing your code, is that you should use the domain option even in the scheduled command, doing something like this, in order to work properly

$domain = app()->domain(); $schedule->command('cleanPdfs', ['--thread'=>'queue','--domain'=>$domain])->everyMinute()->timezone('Asia/Seoul');

Hope this helps

Cheers

Giacomo

gecche commented 3 years ago

Hi,

I close the issue as I didn't receive any feedback

Cheers

Giacomo