Files
exchange-2.0/app/Classes/Modules/Documents/ControllersLogic/ListDocumentJobLogic.php
T
2023-08-24 19:22:20 +08:00

66 lines
1.8 KiB
PHP

<?php
namespace App\Classes\Modules\Documents\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Documents\Services\ListsDocuments;
use App\Classes\Modules\Documents\DataTransferObjects\ListDocumentJobObject;
use App\Classes\Jobs\ListDocuments;
use App\Http\Resources\DocumentResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\General\Helper;
use Illuminate\Support\Facades\Log;
class ListDocumentJobLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'List Job',
'message' => 'You have successfully submit a job to list Documents'
];
}
/**
* @param Request $request
* @return JsonResponse
*/
public function logic(Request $request) : JsonResponse
{
$jobId = uniqid();
Log::error(json_encode($request->all()));
$listDocumentJobObject = new ListDocumentJobObject(
"Proof of Concept",
$request->all(),
$jobId
);
ListDocuments::dispatch($listDocumentJobObject);
// // Create your job instance with delay, so we can back here within delay and take control in our hands.
// $job = new ListDocuments($listDocumentJobObject);
// $job->delay(now()->addSeconds(5));
// // Dispath your job with our custom_dispatch helper. This will return job id from jobs table
// // $jobId = $this->custom_dispatch($job);
$result = [];
$result['job_id'] = $jobId;
return $this->response(['data' => $result]);
}
//cief todo: no longer need jobId
// function custom_dispatch($job): int {
// return app(\Illuminate\Contracts\Bus\Dispatcher::class)->dispatch($job);
// }
}