hsl's avatar
Level 2

Queue example throws error

Hi,

I'm just starting to implement queues in my lumen app and when I copy the example from the documentation I get this error:

App\Jobs\Job and Illuminate\Queue\InteractsWithQueue define the same property ($job) in the composition of App\Jobs\JobName. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed

I'm a bit lost, anyone know how to fix this?

Thanks!

0 likes
10 replies
bashy's avatar

Both those classes define the same $job var/instance? Show some code and there may be something you're doing wrong

hsl's avatar
Level 2

I'm using the example from the documentation: http://lumen.laravel.com/docs/queues I edited it a little to play around with without the mailer/user stuff.

<?php

namespace App\Jobs;

use Test;

use App\Jobs\Job;

use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;

class ProcessTest extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @param  User  $user
     * @return void
     */
    public function __construct( )
    {

    }

    /**
     * Execute the job.
     *
     * @param  Mailer  $mailer
     * @return void
     */
    public function handle()
    {
        
         Log::info('Test Process start');

    }
}
bashy's avatar

Thanks. And this class? App\Jobs\Job;

bashy's avatar

Oh sorry, well in that case, well Job class has InteractsWithQueue already?

I was confused since Laravel renamed Job to Commands so :P

hsl's avatar
Level 2

If I comment this out in /app/Jobs/Job.php

//use Illuminate\Queue\InteractsWithQueue;

I get this error: Fatal error: Trait 'App\Jobs\InteractsWithQueue' not found in /path/to/project/app/Jobs/Job.php on line 10

So it still looks like there is an issue with the documentation.

missaoi's avatar

I had this same issue. I found that I was missing the following component:

https://github.com/illuminate/bus/blob/master/Queueable.php

Then needed to update the Job base class to include Queueable:

https://github.com/laravel/lumen/blob/master/app/Jobs/Job.php

And changed "ShouldQueue" to be "ShouldBeQueued"

My custom job class only extends Job - it doesn't use or implement any other classes or traits, since it's all included in the base Job class.

Seems like a few things were changed around, and the docs got left behind...

dirkweimar's avatar

I was getting the same error.

After checking the Job class in Laravel 5 on GitHub, I observed some differences to the Job class in my fresh Lumen installation. I then found out that copying the Job class from Laravel 5 to Lumen seems to solve the problem.

Job class in Lumen :

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;

abstract class Job implements SelfHandling, ShouldQueue
{
    /*
    |--------------------------------------------------------------------------
    | Queueable Jobs
    |--------------------------------------------------------------------------
    |
    | This job base class provides a central location to place any logic that
    | is shared across all of your jobs. The trait included with the class
    | provides access to the "queueOn" and "delay" queue helper methods.
    |
    */

    use InteractsWithQueue, Queueable, SerializesModels;
}

Job class in Laravel 5:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;


abstract class Job
{
    /*
    |--------------------------------------------------------------------------
    | Queueable Jobs
    |--------------------------------------------------------------------------
    |
    | This job base class provides a central location to place any logic that
    | is shared across all of your jobs. The trait included with the class
    | provides access to the "queueOn" and "delay" queue helper methods.
    |
    */

    use Queueable;
}

Of course, changing the Job class is no option ... so does anybody understand what is causing the above error and why using the Job class from Laravel 5 in Lumen seems to work?

flobauer's avatar

Hello, I am still fresh in both Lumen and Namespacing (so please forgive some Rookieness), the error implied though that we have something "too much". I extend my CustomJobClass from the Main JobClass, therefor I removed the dependencies and injections ( in my CustomJobClass) that were done already in the JobClass.

So I changed the Example Code in my CustomJobClass to:

<?php
namespace App\Jobs;

use App\Jobs\Job;

class StoreResponse extends Job 
{
    public function __construct()
    {}
    public function handle()
    { }
}

It all works fine for me now.

dirkweimar's avatar

Thank you, flobauer -- you put me on the right track.

Removing

use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;

from my derived class did the trick.

2 likes

Please or to participate in this conversation.