Logs job execution in custom logs

This commit is contained in:
Afiq Hamzah
2024-08-09 18:01:31 +08:00
parent 8fd70cd639
commit facf829563
5 changed files with 153 additions and 81 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Jobs;
use App\TransactionOnlineLog;
use Carbon\Carbon ;
class CleanTransactionOnlineLogJob extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$numberOfMonthDeletedBack = 3;
$logger = app('job_log');
$logger->info('Cleaning Transaction Online Log');
try {
TransactionOnlineLog::where('created_at', '<', Carbon::now()->subMonths($numberOfMonthDeletedBack))->get()->each(function ($log) use($logger) {
$logger->info('Deleting Transaction Online Log : ' . $log->id);
$log->delete();
});
} catch (\Exception $e) {
$logger->error($e);
throw $e;
}
}
}