cron fixes.

This commit is contained in:
flash 2021-07-28 22:10:57 +00:00
parent 1bd1e2d16a
commit 31ece58d00

View file

@ -1,10 +1,6 @@
<?php <?php
namespace YTKNS; namespace YTKNS;
// Prevent running cron script during maintenance
if(YTKNS_MAINTENANCE)
return;
if(!defined('YTKNS_SEM_NAME')) if(!defined('YTKNS_SEM_NAME'))
define('YTKNS_SEM_NAME', 'b'); define('YTKNS_SEM_NAME', 'b');
if(!defined('YTKNS_SFM_PATH')) if(!defined('YTKNS_SFM_PATH'))
@ -18,23 +14,26 @@ $semaphore = sem_get($ftok, 1);
if(!sem_acquire($semaphore)) if(!sem_acquire($semaphore))
die('Failed to acquire semaphore.' . PHP_EOL); die('Failed to acquire semaphore.' . PHP_EOL);
require_once __DIR__ . '/startup.php'; try {
require_once __DIR__ . '/startup.php';
// Destroy old sessions // Prevent running cron script during maintenance
UserSession::purge(); if(!YTKNS_MAINTENANCE) {
// Destroy old sessions
UserSession::purge();
// Resynchronise use counts // Resynchronise use counts
Upload::resync(EFFECT_UPLOADS); Upload::resync(EFFECT_UPLOADS);
// Destroy orphaned uploads // Destroy orphaned uploads
Upload::purgeOrphans(); Upload::purgeOrphans();
// Get task queue // Get task queue
$taskQueue = ZoneTask::queue(); $taskQueue = ZoneTask::queue();
// Plow through tasks // Plow through tasks
// TODO: make task functions modular // TODO: make task functions modular
while($task = array_shift($taskQueue)) { while($task = array_shift($taskQueue)) {
if(!isset($zoneInfo) || $zoneInfo->getId() !== $task->getZoneId()) if(!isset($zoneInfo) || $zoneInfo->getId() !== $task->getZoneId())
$zoneInfo = $task->getZone(); $zoneInfo = $task->getZone();
@ -45,6 +44,8 @@ while($task = array_shift($taskQueue)) {
} }
$task->delete(); $task->delete();
}
}
} finally {
sem_release($semaphore);
} }
sem_release($semaphore);