Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Log path from job dispatched #52

Open
TheOneWhoKnokks opened this issue Jun 24, 2021 · 10 comments
Open

Wrong Log path from job dispatched #52

TheOneWhoKnokks opened this issue Jun 24, 2021 · 10 comments

Comments

@TheOneWhoKnokks
Copy link

Hi, first thanks for this package. I'm making some tests and i found maybe an issue.

I'm connected on my site a. I write a log info from a http request, the log write into log file domain (storage/site_a/logs/laravel.log), all good.

But when i write a log inside a job and dispatch this job, the log write in storage/logs/laravel.log and not in storage/site_a/logs/laravel.log.

Any idea why ?

@gecche
Copy link
Owner

gecche commented Jun 24, 2021

Hi,

could you detail how do you launch the job?

Cheers

Giacomo

@TheOneWhoKnokks
Copy link
Author

TheOneWhoKnokks commented Jun 25, 2021

dispatch(new \App\Jobs\TestJob())->onQueue(env('QUEUE_NAME'));

I have a same issue when i call artisan queue :

Artisan::queue('my:command')->onQueue(env('QUEUE_NAME'));

Do i need to specify the domain on each line ?

I tried to pass in param the domain but same result.
Artisan::queue('my:command', ['--domain' => 'my_site'])->onQueue(env('QUEUE_NAME'));

I launch command from web route file for my test

@gecche
Copy link
Owner

gecche commented Jun 25, 2021

Hi,

are you calling the job from the same domain or from another? I.e., this line

Artisan::queue('my:command', ['--domain' => 'my_site'])->onQueue(env('QUEUE_NAME'));

is ran under 'my_site' domain?
Because the launch of artisan commands from within a web route works only for the same domain. And this cannot be changed in any way.

Let me know

Giacomo

@TheOneWhoKnokks
Copy link
Author

Yes i'm calling the job or the command from the same domain.
My domain is my_site.com, i try to launch the job from my_site.com/test.
I'm writing in the log the APP_URL and it's the good value (my_site.com), just the log not write in good path. The env file is correctly loaded but not the storage path

@gecche
Copy link
Owner

gecche commented Jun 25, 2021

Ok... I will investigate asap, even I'm quite busy these days...
which version do you use?

@TheOneWhoKnokks
Copy link
Author

Thank you :) It's not hurry, you can check later when you have times
I'm on laravel 7.30.4 and php 7.2
I will make some test with laravel 8 to verify if i have the same result.

@TheOneWhoKnokks
Copy link
Author

Okay i run some test with laravel 6, 7 and 8. For all versions, it's a fresh laravel install with your package installed.
For the three versions, i write theses lines in bootstrap/app.php, like you example

$domainParams = [
    'domain_detection_function_web' => function() {
        return \Illuminate\Support\Arr::get($_SERVER,'HTTP_HOST');
    }
];

$app = new Gecche\Multidomain\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__), null, $domainParams
);

I make several tests with a command and a job. For both, i write a log info for check where is write the log.
For reproduce my test, you need to :

  • launch a job from a web route
  • launch an artisan queue from a web route with the command specified and Inside the command, write a log and dispatch a job.
  • I use database queue with mysql

I tried with php 7.2, php 7.4 and php 8.0. i have the same issue with laraval 6 and 7.
It's only work on laravel 8 (php 7.4 and 8.0). The log write into the good path

I hope it's can help

@gecche
Copy link
Owner

gecche commented Jun 25, 2021

Thank you very much for your work!

If it works with Laravel 8, I suspect that they have made improvements to the framework which made an improvement to my package too as a side effect :)
Maybe it is not so simple to correct the problem in previous versions... anyway I will try asap...

Cheers

Giacomo

@TheOneWhoKnokks
Copy link
Author

I think i found where is the issue, it's on QueueServiceProdiver.
On laravel 8, you use the register method

public function register()
    {
        parent::register();

        $this->app->extend('command.queue.listen', function ($command, $app) {
            return new QueueListenCommand($app['queue.listener']);
        });
    }

On laravel 6 and 7

public function boot()
    {

        $this->app->singleton('command.queue.listen', function ($app) {
            return new QueueListenCommand($app['queue.listener']);
        });
    }

I tried to replace the boot method with the register method and set the same content from laravel 8 in laravel 7 provider and it works.
I also tried to change the $this->app->singleton into $this->app->extend in the boot method without recreate the register method and it work too.
I don't know if there is something else but it's a start :)

@gecche
Copy link
Owner

gecche commented Jul 4, 2021

Sorry for the delay... however I think that you are right... the changes you indicated (together with others) have been implemented by another user in order to get Horizon working properly with my package and I didn't propagate the changes to previous versions of the package.
I'm currently off until Thursday: I will propagate the changes doing some test asap and I will close the issue.
Thank you very much for the support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants