Reputation: 7895
how may i get access to a job id
in laravel 5.2?
regarding to this link i have tried getJobId()
, but doesn't work.
ofcourse when i get a log using dd()
thers is an id
but probably its protected.so i cant access it.
#job: {#459
+"id": 233
+"queue": "offers"
+"payload": "{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":....}"
+"attempts": 50
+"reserved": 0
+"reserved_at": null
+"available_at": 1464615540
+"created_at": 1464615540
}
Upvotes: 1
Views: 5110
Reputation: 379
In the L5.3 you can get Job Id this way
inside your job class
<?php
namespace App\Jobs;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ParseUniversityData implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $user;
/**
* Create a new job instance.
*
* @param $userId
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Execute the job.
*
* @throws \Exception
* @return void
*/
public function handle()
{
$jobId = $this->job->getJobId(); // this how you can get job id
}
}
the method where you dispatch your job (in this example I'm using action method in my controller)
public function someExampleAction(Request $request)
{
$requestData = $request->all();
$job = (new someExampleJob(
$requestData['property'], $user
));
$jobId = dispatch($job); // this is variable job id
}
Upvotes: 5
Reputation: 17
public function handle()
{
$jobid=$this->job->getJobId();
}
you can get the job id by this method
Upvotes: -1