Example #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');
 }
Example #2
0
function QueueCacheRequest($model, $method, $args)
{
    \App\CacheQueue::firstOrCreate(['model' => "\\" . $model, 'method' => $method, 'args' => $args]);
    return true;
}