added jobs in account check
This commit is contained in:
@@ -60,6 +60,9 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Jobs\AccountCheckJob;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdminPageController extends Controller
|
||||
{
|
||||
@@ -3834,15 +3837,20 @@ class AdminPageController extends Controller
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->simplePaginate(5);
|
||||
$check = app(AccountService::class);
|
||||
$array_all = ['current_page' => $cawangan->currentPage()];
|
||||
$array_all = ['current_page' => $cawangan->currentPage(), 'job_ids' => []];
|
||||
foreach($cawangan as $caw){
|
||||
try{
|
||||
$test =$check->checkAccount($caw['kodcaw'],$request->month);
|
||||
$array_all['data'][$caw['details_caw']] = $test;
|
||||
$jobId = Str::uuid();
|
||||
$res = dispatch(new AccountCheckJob($caw['kodcaw'], $request->month,$jobId));
|
||||
// $array_all['data'][$caw['details_caw']] = $res;
|
||||
$array_all['data'][$caw['details_caw']] = [
|
||||
'jobId' => $jobId,
|
||||
'status' => 'queued',
|
||||
];
|
||||
$array_all['job_ids'][] = $jobId;
|
||||
}catch(\Exception $e){
|
||||
Log::error($caw['kodcaw']);
|
||||
Log::error("Error processing: " . $caw['kodcaw']);
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3850,4 +3858,19 @@ class AdminPageController extends Controller
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function getJobStatus(Request $request)
|
||||
{
|
||||
$jobId = $request->input('jobId');
|
||||
|
||||
// Get the job status and result from cache (or database)
|
||||
$status = Cache::get("job_status_{$jobId}", 'not_found');
|
||||
$result = Cache::get("job_result_{$jobId}", []);
|
||||
|
||||
// Return both the status and the result
|
||||
return response()->json([
|
||||
'status' => $status,
|
||||
'result' => $status === 'completed' ? $result : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Services\Reports\AccountService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AccountCheckJob implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $kodcaw;
|
||||
protected $month;
|
||||
protected $jobId;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($kodcaw, $month, $jobId)
|
||||
{
|
||||
$this->kodcaw = $kodcaw;
|
||||
$this->month = $month;
|
||||
$this->jobId = $jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$logger = app('job_log');
|
||||
|
||||
try {
|
||||
$check = app(AccountService::class);
|
||||
$test =$check->checkAccount( $this->kodcaw,$this->month);
|
||||
Cache::put("job_result_{$this->jobId}", $test, Carbon::now()->addMinutes(10));
|
||||
Cache::put("job_status_{$this->jobId}", 'completed', Carbon::now()->addMinutes(10));
|
||||
} catch (\Exception $e) {
|
||||
$logger->error($e);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -851,7 +851,8 @@ $router->group(['prefix'=>'admin'], function () use ($router){
|
||||
$router->get('ig/bayaran_penghutang',['uses'=>'AdminPageController@SenaraiBayaranHutang']);
|
||||
|
||||
$router->get('get/accountcheck',['uses'=>'AdminPageController@getAccountList']);
|
||||
|
||||
$router->post('get/jobstatus',['uses'=>'AdminPageController@getJobStatus']);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user