conversationMapper = $conversationMapper; $this->logger = $logger; // Run once per day (24 hours = 86400 seconds) $this->setInterval(86400); // Use random time-sensitivity to spread load across instances // This prevents all instances from running cleanup at the exact same time $this->setTimeSensitivity(self::TIME_INSENSITIVE); } /** * @param array $arguments */ protected function run($arguments): void { $retentionDays = $arguments['retention_days'] ?? self::DEFAULT_RETENTION_DAYS; if (!is_int($retentionDays) || $retentionDays < 1) { $retentionDays = self::DEFAULT_RETENTION_DAYS; } // Calculate cutoff timestamp $cutoffTimestamp = time() - ($retentionDays * 24 * 60 * 60); $this->logger->info('EducAI: Starting conversation cleanup job', [ 'retention_days' => $retentionDays, 'cutoff_date' => date('Y-m-d H:i:s', $cutoffTimestamp), ]); try { $this->conversationMapper->deleteOlderThan($cutoffTimestamp); $this->logger->info('EducAI: Conversation cleanup completed successfully', [ 'cutoff_timestamp' => $cutoffTimestamp, ]); } catch (\Throwable $e) { $this->logger->error('EducAI: Conversation cleanup failed', [ 'exception' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); } } }