Files
exchange-2.0/app/Classes/Jobs/ListDocuments.php
T

62 lines
1.8 KiB
PHP

<?php
namespace App\Classes\Jobs;
use App\Classes\Modules\Documents\Processors\ListDocumentJobProcessor;
use App\Classes\Modules\Generic\DataTransferObjects\ListGenericJobObject;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\JobResult;
use Illuminate\Support\Facades\Log;
class ListDocuments implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** @var ListGenericJobObject */
private $listGenericJobObject;
private $jobId;
/**
* ListDocuments constructor.
* @param ListGenericJobObject $listGenericJobObject
*/
public function __construct(ListGenericJobObject $listGenericJobObject)
{
$this->listGenericJobObject = $listGenericJobObject;
}
public function handle()
{
$rawPayload = $this->job->payload();
if(isset($rawPayload['data']['commandName'])){
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
}
if(isset($rawPayload['data']['command'])){
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
}
$result = (App()->make(ListDocumentJobProcessor::class))->execute($this->listGenericJobObject);
//cief todo: Insert into DB: job id, query result, timestamp
// Store the result in the job_results table
//cief todo: why cannot save data in table like this
// $model = new JobResult();
// $model->job_id = $this->job->getJobId();
// $model->result = json_encode($result);
// $model->save();
// Log::error(json_encode($model->id));
}
public function getJobId(){
return $this->job->getJobId();
}
}