option('data')[0]); $audit_service = $this->option('audit_service'); if (!filter_var($audit_service, FILTER_VALIDATE_BOOLEAN)){ $this->start(); }else{ event(new EventAuditorService(LoanManagementAuditService::doubleDueDate, $data)); event(new EventAuditorService(LoanManagementAuditService::duplicateEMIInEMICalculation, $data)); event(new EventAuditorService(LoanManagementAuditService::emiDateAnomaliesInEMIPayments, $data)); } } public function start(){ $this->auditQueue = new AuditQueue(); $auditLogs = $this->getJobs(); foreach ($auditLogs as $auditLog) { try { $this->updateJob($auditLog, ListenerAuditService::QUEUE); $this->runCommand($auditLog); }catch (\Exception $e){ $this->updateJob($auditLog, ListenerAuditService::FAILED, ['error' => [ 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine() ]]); } } } public function runCommand($auditLog){ $handler = json_decode($auditLog->input); $function = $handler->initiator[0]; $className = $handler->initiator[1]; if (class_exists($className)) { if (method_exists($className, $function)) { $classObject = new $className(new Request((array)$handler)); $output = $classObject->$function(); $this->updateJob($auditLog, ListenerAuditService::COMPLETED, $output); } } } private function getJobs(){ return $this->auditQueue::where('status', ListenerAuditService::PENDING)->orderBy('created_at','desc')->limit(20)->get(); } private function updateJob($auditLog, $status, $output = null){ $this->auditQueue::where('id', $auditLog->id)->update(['status' => $status, 'attempt_count' => DB::raw('attempt_count+1'), 'output' => json_encode($output)]); } }