Files
citrus-cms/resources/views/cron.blade.php
T
2026-04-28 21:15:09 +03:00

272 lines
8.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@if(!getisset("type"))
<?php
$result = Artisan::call('schedule:run');
dump("Schedule run: $result");
?>
@include("cron-register-creator")
<?php
// Check if current time is within night shift hours (20:00 to 07:00)
$currentHour = (int) date("H");
$isNightShift = ($currentHour >= 20 || $currentHour < 7);
if ($isNightShift) {
dump("Night shift");
} else {
dump("Day shift");
}
?>
@if($isNightShift)
@include("cron-report-builder-queue")
@endif
@endif
<?php
ini_set('memory_limit', '8G');
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
set_time_limit(-1);
ini_set('max_execution_time', -1);
$adminMail = env("ADMIN_MAIL");
// Regular cron jobs working time
$workingTime = [
// '12:00',
// '12:00',
'23:00',
'02:00',
//'10:30',
];
// Cache-blade cron jobs working time - separate schedule
$cacheWorkingTime = [
'06:00',
'09:00',
'12:00',
'15:00',
'18:00',
'21:00',
'00:00',
'03:00',
];
$cronJobPeriod = setting('cron_job_period');
$oneMinuteAgo = Carbon::now()->subMinutes($cronJobPeriod);
$take = setting('cron_job_batch_process_count');
$saat = date("H:i");
$dakika = (int) date("i");
$period = 30;
$kalan = $dakika % $period;
$commitSize = 250;
// Determine whether to process cache files or regular files based on current time
$isCacheTime = in_array($saat, $cacheWorkingTime);
$isRegularTime = in_array($saat, $workingTime);
if(!getisset("type"))
{
// Only allow the script to run at specified times
if (getisset("cache")) {
// If cache parameter is explicitly provided, use it to override time-based decision
$runCacheFiles = get("cache") == 1;
if ($runCacheFiles && !$isCacheTime) {
dump($saat);
dump($cacheWorkingTime);
dump("Cache Working Time Out");
exit();
} else if (!$runCacheFiles && !$isRegularTime) {
dump($saat);
dump($workingTime);
dump("Working Time Out");
exit();
}
} else {
// No cache parameter - automatically decide based on current time
if (!$isCacheTime && !$isRegularTime) {
dump($saat);
dump("Working Time Out - Not in any scheduled time");
dump("Regular times: " . implode(", ", $workingTime));
dump("Cache times: " . implode(", ", $cacheWorkingTime));
exit();
}
// If both cache and regular time overlap, cache takes precedence
}
}
Cache::forget("cronjob");
if(!getesit("type","")) {
Cache::forget("cronjob");
}
if($saat == "11:00")
{
Cache::forget("cronjob");
dump("forget cronjob");
}
if(!Cache::has("cronjob")) {
// if($kalan == 0) {
$start = new Carbon(simdi());
Cache::put("cronjob", simdi());
Log::debug("🟢 cron start: " . simdi());
// Get all blade files from cron directory
$allFiles = glob(base_path() . '/resources/views/cron/*.blade.php');
// Separate cache-blade files from other files
$cacheFiles = [];
$regularFiles = [];
foreach($allFiles as $file) {
$basename = basename($file);
if(strpos($basename, 'cache-blade') === 0) {
$cacheFiles[] = $file;
} else {
$regularFiles[] = $file;
}
}
// Determine which files to process based on request or time
$filesToProcess = [];
if(getisset("type")) {
// If specific type is requested, include only that file
$filesToProcess = $allFiles;
} else if(getisset("cache")) {
// If cache parameter is explicitly provided
$runCacheFiles = get("cache") == 1;
if($runCacheFiles) {
$filesToProcess = $cacheFiles;
Log::debug("Processing only cache-blade files (explicit): " . count($cacheFiles));
} else {
$filesToProcess = $regularFiles;
Log::debug("Processing regular cron files (explicit): " . count($regularFiles));
}
} else {
// Auto determine based on current time
// If both time ranges overlap, cache takes precedence
if($isCacheTime) {
$filesToProcess = $cacheFiles;
Log::debug("Processing cache-blade files (auto time-based): " . count($cacheFiles));
} else if($isRegularTime) {
$filesToProcess = $regularFiles;
Log::debug("Processing regular cron files (auto time-based): " . count($regularFiles));
} else {
// This shouldn't happen due to earlier check, but just in case
$filesToProcess = [];
Log::debug("No files to process - not in any scheduled time");
}
}
$count = 0;
$total = count($filesToProcess);
?>
@if(!getesit("type",""))
@includeIf('cron.' . get("type"))
@else
@foreach ($filesToProcess as $file)
<?php
//ob_start();
$description = basename($file);
$description = str_replace(".blade.php", "", $description);
Log::info($file);
Cache::put("cronjob_progress", [
'total' => $total,
'count' => $count,
'progress' => round($count * 100 / $total),
'description' => $description,
'start' => simdi()
]);
$count++;
try {
?>
@include('cron.' . basename(str_replace('.blade.php', '', $file)))
<?php
} catch (\Throwable $th) {
Log::error("cron");
Log::error($th->getMessage());
Cache::forget("cronjob");
dump($th);
mailSend($adminMail, env("APP_NAME")." Cron Job Error", $th->getMessage());
}
?>
<?php
// ob_end_clean();
//gc_collect_cycles();
?>
@endforeach
@endif
<?php
$end = new Carbon(simdi());
if(!getisset("type")) {
Cache::put("cronjob_progress", [
'total' => $total,
'count' => $total,
'progress' => 100,
'start' => simdi(),
'description' => "finish " . simdi() . " " . $start->diff($end)->format('%H:%I:%S')
]);
}
Log::debug("🔴 cron finish: " . simdi());
Log::debug("⏰ süre: " . $start->diff($end)->format('%H:%I:%S'));
Cache::forget("cronjob");
//.. mailSend($adminMail, env("APP_NAME")." Cron Job Finished", "Cron Job Finished");
/*
} else {
// dump($period - $kalan);
dump("Cron ". $period - $kalan ." dakika sonra çalışacak");
}
*/
?>
<?php
} else {
$runControlAttempt = Cache::get("cronJobRunControlAttempt");
if(is_null($runControlAttempt))
{
$runControlAttempt = 0;
}
$runControlAttempt++;
Cache::put("cronJobRunControlAttempt", $runControlAttempt);
if($runControlAttempt == 100)
{
Cache::forget("cronjob");
Cache::forget("cronJobRunControlAttempt");
Log::debug("Cron job 100 dakikadır çalışıyor. Tekrar başlatılacak...");
}
dump("cronJobRunControlAttempt $runControlAttempt");
dump("Çalışan bir cron var onun bitmesini bekliyorum");
Log::debug("Çalışan bir cron var onun bitmesini bekliyorum");
}
?>