Exemplo n.º 1
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->command('export-monster-files test')->cron('00 * * * *')->name('process-feed')->withoutOverlapping();
     $schedule->call(function () {
         $files = \App\FileDeleteQueue::all();
         foreach ($files as $file) {
             $local_file = config('monster.tmp_storage_path') . $file->file_name;
             if (file_exists($local_file)) {
                 $tmp_is_deleted = unlink(realpath($local_file));
                 if (!$tmp_is_deleted) {
                     \App\ExportLog::create(['process' => 'deleting local file', 'filename' => $ftp_file, 'message' => 'cannot be deleted from /tmp/ folder']);
                 } else {
                     $file->delete();
                 }
             }
         }
     })->name('delete-local-files')->twiceDaily(12, 23);
     $schedule->call(function () {
         // deleting expired jobs
         $today = date('Y-m-d', time());
         $jobs = \App\Job::where('end_date', '<', $today)->take(1000)->get();
         if (!$jobs->isEmpty()) {
             $i = 0;
             foreach ($jobs as $j) {
                 $j->delete();
                 $i++;
             }
             \App\ExportLog::create(['process' => 'deleting expired jobs', 'message' => 'Deleted ' . $i . ' jobs']);
         }
     })->cron('5 * * * *')->name('delete-expired-jobs-hourly')->withoutOverlapping();
     $schedule->call(function () {
         $today = date('Y-m-d', time() - 3 * 86400);
         \App\ExportRecordFailure::where('created_at', '<', $today)->take(3000)->delete();
     })->cron('5 * * * *')->name('delete-export-record-failures')->withoutOverlapping();
     $schedule->call(function () {
         $queue = \App\CacheQueue::where(['in_process' => 0])->take(10);
         $records = $queue->get();
         if (!$records->isEmpty()) {
             $queue->update(['in_process' => 1]);
             foreach ($records as $record) {
                 $run = call_user_func($record->model . '::' . $record->method, $record->args);
                 if ($run) {
                     $record->delete();
                 } else {
                     $record->in_process = null;
                     $record->save();
                 }
             }
         }
     })->everyMinute()->name('process-cache-queue-records');
 }
Exemplo n.º 2
0
 private static function prepareJobRecord($data)
 {
     $currentRecord = [];
     // VALIDATE DATA
     if (empty($data->external_job_id)) {
         ExportRecordFailure::create(['job_info' => json_encode($data), 'reason' => '[ external_job_id is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     }
     if (empty($data->job_title)) {
         ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ title is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     }
     $end_date = null;
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_end_date, $end_date_matches)) {
         $end_date_mm = $end_date_matches[2];
         $end_date_dd = $end_date_matches[3];
         $end_date_yyyy = $end_date_matches[1];
         $end_date = $end_date_yyyy . '-' . $end_date_mm . "-" . $end_date_dd;
     }
     if (empty($end_date)) {
         ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ end date is missing ]', 'action' => '[ exiting process ]', 'calling_function' => __FUNCTION__]);
         return null;
     } else {
         $jobObj = Job::firstOrNew(['external_job_id' => $data->external_job_id, 'source_id' => 1]);
         if (strtotime($end_date) < strtotime(date('Y-m-d'))) {
             if (!empty($jobObj->id)) {
                 $record_id = $jobObj->id;
                 $jobObj->delete();
                 ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ]', 'action' => '[ record deleted ][ record id: ' . $record_id . ' ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
                 return $record_id;
             } else {
                 ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ] ', 'action' => '[ will not create a record ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
                 $jobObj = null;
                 return 1;
             }
         }
     }
     if (!empty($data->job_state) && $data->job_state == 'expired') {
         if (!empty($jobObj->id)) {
             $record_id = $jobObj->id;
             $jobObj->delete();
             ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ]', 'action' => '[ record deleted ][ record id: ' . $record_id . ' ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
             return $record_id;
         } else {
             ExportRecordFailure::create(['external_job_id' => $data->external_job_id, 'job_info' => json_encode($data), 'reason' => '[ expired job ] ', 'action' => '[ will not create a record ] [ exiting process ]', 'calling_function' => __FUNCTION__]);
             $jobObj = null;
             return 1;
         }
     }
     // END OF DATA VALIDATION
     if (!empty($jobObj->id)) {
         $currentRecord = Job::getInfo($jobObj->id, ['JobState', 'JobCity', 'JobCompany', 'JobCategory', 'JobIndustry']);
     }
     $jobObj->source_id = 1;
     $jobObj->external_job_id = $data->external_job_id;
     if (!empty($data->job_name)) {
         $jobObj->name = self::cleanUpStr($data->job_name);
     }
     if (!empty($data->job_title)) {
         $jobObj->title = self::cleanUpStr($data->job_title);
     }
     if (!empty($data->org_name)) {
         $company_name = trim(str_replace("&apos;", "'", $data->org_name));
     } else {
         $company_name = 'Confidential';
     }
     if (empty($currentRecord) || $currentRecord['JobCompany'] != $company_name) {
         $company_obj = Company::saveInstance(['name' => $company_name]);
         $jobObj->company_id = $company_obj->id;
     }
     $jobObj->apply_url = 'http://jobview.monster.com/getjob.aspx?jobid=' . $data->external_job_id;
     if ($company_name == 'Comcast Cable Communications Management, LLC') {
         if (!empty($data->apply_url)) {
             $jobObj->apply_url = $data->apply_url;
         }
     }
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_begin_date, $begin_date_matches)) {
         $begin_date_mm = $begin_date_matches[2];
         $begin_date_dd = $begin_date_matches[3];
         $begin_date_yyyy = $begin_date_matches[1];
         $jobObj->begin_date = $begin_date_yyyy . '-' . $begin_date_mm . '-' . $begin_date_dd;
     }
     $jobObj->end_date = $end_date;
     if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T.*\$/", $data->job_post_date, $post_date_matches)) {
         $post_date_mm = $post_date_matches[2];
         $post_date_dd = $post_date_matches[3];
         $post_date_yyyy = $post_date_matches[1];
         $jobObj->post_date = $post_date_yyyy . '-' . $post_date_mm . '-' . $post_date_dd;
     }
     if (!empty($data->job_category)) {
         if (empty($currentRecord) || $currentRecord['JobCategory'] != $data->job_category) {
             $cat_obj = Category::firstOrCreate(['name' => $data->job_category]);
             $jobObj->category_id = $cat_obj->id;
         }
     }
     if (!empty($data->job_industries[0])) {
         if (empty($currentRecord) || $currentRecord['JobIndustry'] != $data->job_industries[0]) {
             $ind_obj = Industry::firstOrCreate(['name' => $data->job_industries[0]]);
             $jobObj->industry_id = $ind_obj->id;
         }
     }
     if (isset($data->location) && !empty($data->location)) {
         $location = $data->location;
         if (!empty(trim($location->city))) {
             $jobObj->city = trim($location->city);
         }
         if (!empty(trim($location->state))) {
             $jobObj->state = trim($location->state);
         }
         if (!empty(trim($location->country))) {
             $jobObj->country = trim($location->country);
         }
         if (isset($location->zip) && !empty(trim($location->zip))) {
             if (trim($location->zip) == '00000') {
                 $jobObj->zip = null;
             } else {
                 $jobObj->zip = trim($location->zip);
             }
         }
         if (!empty($jobObj->city) && !empty($jobObj->state)) {
             if (empty($currentRecord) || $currentRecord['JobCity'] != $jobObj->city || $currentRecord['JobState'] != $jobObj->state) {
                 $dma_obj = DmaMap::where(['city' => $jobObj->city, 'state_abbr' => $jobObj->state])->first();
                 if (!empty($dma_obj)) {
                     $jobObj->dma_code = $dma_obj->code;
                 }
             }
         }
     }
     return $jobObj;
 }
Exemplo n.º 3
0
 public static function saveInstance(Job $jobObj)
 {
     $old_keywords = '';
     $record_status = 'new';
     if (!empty($jobObj->id)) {
         // updating record
         $currentData = self::getInfo($jobObj->id, ['JobTitle', 'JobKeywords', 'JobDmaCode', 'JobCompanyId', 'JobCompanyStrId', 'JobCompany']);
         // we need to comapare data to manage caches
         $currentDmaCode = $currentData['JobDmaCode'];
         $currentCompanyIdStr = $currentData['JobCompanyId'];
         if ($currentData['JobTitle'] != $jobObj->title) {
             // reset keywords
             $old_keywords = $currentData['JobKeywords'];
         }
         if ($currentData['JobDmaCode'] != $jobObj->dma_code) {
             // remove from dma cache
             self::removeJobFromDmaCache($currentData['JobDmaCode'], $jobObj->id);
         }
         if ($currentData['JobCompanyId'] != $jobObj->company_id) {
             Company::removeJobFromCompanyCache($currentData['JobCompanyStrId'], $jobObj->id);
         }
         $record_status = 'existed';
         //$jobObj->updated_at = date('Y-m-d H:i:s');
     }
     $is_saved = $jobObj->save();
     $job_id = $jobObj->id;
     if (empty($job_id)) {
         ExportRecordFailure::create(['job_info' => json_encode($attr), 'reason' => '[ failed to create|update a DB record ]', 'calling_function' => __FUNCTION__]);
         return null;
     } else {
         // process job keywords
         self::processKeywords($jobObj, $record_status, $old_keywords);
         // update/add to all nessecary caches
         self::addToCaches($job_id);
         return $job_id;
     }
 }