Search code examples
phplaravellaravel-4task-queuebeanstalkd

Undefined property: Illuminate\Queue\Jobs\BeanstalkdJob:: $name


I'm using beanstalkd with Laravel to queue some tasks but I'm having trouble to send data to the function that handles the queue , Here is my code

//Where I call the function 

$object_st = new stdClass(); 
$object_st->Person_id = 2 ;

//If I do this: echo($object_st->Person_id); , I get 2 

Queue::push('My_Queue_Class@My_Queue_Function', $object_st );

And the function that handle the queue is the following

 public function My_Queue_Function( $Data )
{
    $Person_id = $Data->Person_id; //This generate the error 

    //Other code
}

The error says:

[ErrorException]
Undefined property: Illuminate\Queue\Jobs\BeanstalkdJob::$Person_id


Solution

  • The way queues work in 4.2 is different than 5; the first argument in the function that handles the queue task is actually a queue job instance, the second argument would be your data:

    class SendEmail {
    
        public function fire($job, $data)
        {
            //
        }
    
    }
    

    As per example from the documentation.

    Your code would therefor need to allow the first argument:

    public function My_Queue_Function( $job, $Data )
    {
        $Person_id = $Data['Person_id'];
    
        //Other code
    }