/** * Job handler. * * @param Illuminate\Queue\Jobs\Job $job * @param string[] */ public function fire($job, $data) { if (is_null($data) || $job->attempts() > 2) { $this->log->error('Failed importing job', $data); $job->delete(); return; } //Extract data $input = $data['input']; $settings = $data['settings']; $importable_model = new $data['importable-model'](); //Initialize importer $this->importer->setModel($importable_model); $this->importer->setSettings($settings); //Import data if (!$this->importer->import($input)) { $this->log->error('Import job validation errors', $this->importer->validationErrors()->toArray()); $job->delete(); return; } //Log results if ($this->log_import) { $this->log->warning('Import job errors', $this->importer->errors()->toArray()); } $this->log->info('Import job result', [$data['importable-model'] => $this->importer->getImported()]); $job->delete(); }
public function fire(Illuminate\Queue\Jobs\Job $job, $data) { $check = Check::findOrFail($data); $headers = array(); $options = array(); if (!empty($check->username)) { $options['auth'] = array($check->username, $check->password); } try { $latencyStart = microtime(true); $response = Requests::get($check->url, $headers, $options); $latency = round((microtime(true) - $latencyStart) * 1000); } catch (Requests_Exception $e) { $latency = round((microtime(true) - $latencyStart) * 1000); if (CheckResult::create(array('check_id' => $check->id, 'status_code' => 0, 'success' => false, 'latency' => $latency, 'content' => trans('check.errors.resolve-host', array('host' => $check->url))))) { $job->delete(); } else { $job->release(); } return true; } $lastCheck = CheckResult::where('check_id', '=', $check->id)->orderBy('created_at', 'desc')->first(); if ($response->success) { if (isset($lastCheck) && !$lastCheck->success) { Mail::queue('email.check.online', array('id' => $check->id, 'title' => $check->title), function ($message) use($check) { $message->to($check->theUser->email)->subject(trans('check.job.email.online.subject', array('title' => $check->title))); }); } if (CheckResult::create(array('check_id' => $check->id, 'status_code' => $response->status_code, 'success' => true, 'latency' => $latency))) { $job->delete(); } else { $job->release(); } } else { if (isset($lastCheck) && $lastCheck->success) { Mail::queue('email.check.offline', array('id' => $check->id, 'title' => $check->title, 'statusCode' => $response->status_code), function ($message) use($check) { $message->to($check->theUser->email)->subject(trans('check.job.email.offline.subject', array('title' => $check->title))); }); } if (CheckResult::create(array('check_id' => $check->id, 'status_code' => $response->status_code, 'success' => false, 'content' => $response->body, 'headers' => json_encode($response->headers), 'latency' => $latency))) { $job->delete(); } else { $job->release(); } } }