= TIMESTAMP( DATE_ADD(updated_at, INTERVAL `run_every` HOUR )) */ protected function process(InputInterface $input, OutputInterface $output, SymfonyStyle $io) { $io->title('Snapshots schedule: Starting'); $productIds = ProductConfiguration::ofSetting('permissionSnapshotJob') ->where("value", "not like", '\"\"') ->pluck("product_id") ->all(); if (empty($productIds)) { $io->error("Scheduled Snapshot Jobs is not configured"); return; } $h = (new Hosting())->getTable(); $sj = (new SnapshotJob())->getTable(); $entities = SnapshotJob::select("{$sj}.*") ->leftJoin($h, "{$h}.id", '=', "{$sj}.hosting_id") ->whereRaw("{$sj}.period = 'daily' AND TIMESTAMP({$sj}.start_time) < TIMESTAMP(NOW()) AND TIMESTAMP({$sj}.updated_at) < TIMESTAMP({$sj}.start_time) OR ( {$sj}.period = 'daily' AND {$sj}.start_time IS NULL AND DATE({$sj}.updated_at) != DATE(NOW()) ) OR ( {$sj}.period = 'hourly' AND TIMESTAMP(NOW()) >= TIMESTAMP( DATE_ADD({$sj}.updated_at, INTERVAL {$sj}.run_every HOUR )) ) ") ->where("{$h}.domainstatus", "Active") ->whereIn("{$h}.packageid", $productIds); $i = 0; /** * DAYName(NOW()) Friday * @var SnapshotJob $entity */ foreach ($entities->get() as $entity) { try { $now = new \DateTime(); $today = $now->format("l"); if($entity->period == "daily" && ( $entity->days && !in_array($today, $entity->days) ) ){ continue; } $i++; $output->writeln(sprintf("Synchronize snapshot job #%s (Hosting ID %s)",$entity->id, $entity->hosting_id)); if(!Job::waiting()->ofJob(SnapshotVmJob::class)->ofHostingId($entity->hosting_id)->count()){ $job=["snapshotJobId"=> $entity->id]; queue(SnapshotVmJob::class, $job, null, "hosting", $entity->hosting_id); $entity->update(['updated_at' => date("Y-m-d H:i:s")]); $output->writeln(sprintf("Snapshot job #%s has been synchronized", $entity->id)); } }catch (\Exception $ex) { $io->error( $ex->getMessage()); } } $output->writeln(""); $io->success([ sprintf("Synchronize snapshots schedule: %s Entries Processed.", $i), "Snapshots schedule: Done" ]); } }