<commit_before><?php
/**
 * Will schedual execution of external commands
 * Copied base functionality from KScheduler
 *
 * @package Scheduler
 */
class KGenericScheduler
{
	/**
	 * @var bool
	 */
	private $enableDebug = true;

	/**
	 * @var KSchedulerConfig
	 */
	private $schedulerConfig = null;

	/**
	 * @var bool
	 */
	private $keepRunning = true;

	private $logDir = "opt/kaltura/log";
	private $phpPath = null;
	private $statusInterval;
	private $schedulerStatusInterval;
	private $nextStatusTime = 0;
	private $nextSchedulerStatusTime = 0;
	private $logWorkerInterval;

	/**
	 * Stores all groups of tasks, the index is the task type
	 * @var array is an array of array
	 */
	private $runningTasks = array();

	/**
	 * Stores the last execution time of each task type
	 * @var array
	 */
	private $lastRunTime = array();

	/**
	 * Stores the last executed index of each task type
	 * @var array
	 */
	private $nextRunIndex = array();
	
	/**
	 * Stores the size of the queue on the server of each task type
	 * @var array
	 */
	private $queueSizes = array();

	/**
	 * Stores the last time each worker had a log issued.
	 * @var array
	 */
	private $lastWorkerLog = array();

	/**
	 * @param string $phpPath
	 * @param string $configFileName
	 */
	public function __construct($phpPath, $configFileName)
	{
		$this->phpPath = $phpPath;
		$this->loadConfig($configFileName);
	}

	public function __destruct()
	{
		$this->_cleanup();
	}
	
	/**
	 * Loads the configuration file and initializes the scheduler accordingly.
	 * Inits all workers
	 * @param string $configFileName
	 */
	private function loadConfig($configFileName = null)
	{
		$firstLoad = is_null($this->schedulerConfig);
		if($firstLoad)
		{
			$this->schedulerConfig = new KSchedulerConfig($configFileName);
			date_default_timezone_set($this->schedulerConfig->getTimezone());

			$pid = $this->schedulerConfig->getPidFileDir() . '/batch.pid';
			if(file_exists($pid))
			{
				KalturaLog::err("Scheduler already running - pid[" . file_get_contents($pid) . "]");
				exit(1);
			}
			file_put_contents($pid, getmypid());

			KalturaLog::info(file_get_contents('VERSION.txt'));
			
			$this->loadRunningTasks();
		}
		else
		{
			if(!$this->schedulerConfig->reloadRequired())
			{
				return;
			}
			if (!$this->schedulerConfig->load())
			{
				return;
			}
		}

		KScheduleHelperManager::clearFilters();

		$this->queueSizes = array();

		$configItems = $this->createConfigItem($this->schedulerConfig->toArray());
		$taskConfigs = $this->schedulerConfig->getTaskConfigList();

		$this->logDir = $this->schedulerConfig->getLogDir();
		$this->statusInterval = $this->schedulerConfig->getStatusInterval();
		$this->schedulerStatusInterval = $this->schedulerConfig->getSchedulerStatusInterval();
		KDwhClient::setEnabled($this->schedulerConfig->getDwhEnabled());
		KDwhClient::setFileName($this->schedulerConfig->getDwhPath());<commit_msg>NO-PLAT - fix batch config loading crash<commit_after><?php
/**
 * Will schedual execution of external commands
 * Copied base functionality from KScheduler
 *
 * @package Scheduler
 */
class KGenericScheduler
{
	/**
	 * @var bool
	 */
	private $enableDebug = true;

	/**
	 * @var KSchedulerConfig
	 */
	private $schedulerConfig = null;

	/**
	 * @var bool
	 */
	private $keepRunning = true;

	private $logDir = "opt/kaltura/log";
	private $phpPath = null;
	private $statusInterval;
	private $schedulerStatusInterval;
	private $nextStatusTime = 0;
	private $nextSchedulerStatusTime = 0;
	private $logWorkerInterval;

	/**
	 * Stores all groups of tasks, the index is the task type
	 * @var array is an array of array
	 */
	private $runningTasks = array();

	/**
	 * Stores the last execution time of each task type
	 * @var array
	 */
	private $lastRunTime = array();

	/**
	 * Stores the last executed index of each task type
	 * @var array
	 */
	private $nextRunIndex = array();
	
	/**
	 * Stores the size of the queue on the server of each task type
	 * @var array
	 */
	private $queueSizes = array();

	/**
	 * Stores the last time each worker had a log issued.
	 * @var array
	 */
	private $lastWorkerLog = array();

	/**
	 * @param string $phpPath
	 * @param string $configFileName
	 */
	public function __construct($phpPath, $configFileName)
	{
		$this->phpPath = $phpPath;
		$this->loadConfig($configFileName);
	}

	public function __destruct()
	{
		$this->_cleanup();
	}
	
	/**
	 * Loads the configuration file and initializes the scheduler accordingly.
	 * Inits all workers
	 * @param string $configFileName
	 */
	private function loadConfig($configFileName = null)
	{
		$firstLoad = is_null($this->schedulerConfig);
		if($firstLoad)
		{
			try
			{
				$this->schedulerConfig = new KSchedulerConfig($configFileName);
			}
			catch(Exception $e)
			{
				KalturaLog::alert("Error loading configuration from api servers!!! " . $e->getMessage());
				exit(1);
			}
			date_default_timezone_set($this->schedulerConfig->getTimezone());
			$pid = $this->schedulerConfig->getPidFileDir() . '/batch.pid';
			if(file_exists($pid))
			{
				KalturaLog::err("Scheduler already running - pid[" . file_get_contents($pid) . "]");
				exit(1);
			}
			file_put_contents($pid, getmypid());

			KalturaLog::info(file_get_contents('VERSION.txt'));

			$this->loadRunningTasks();
		}
		else
		{
			if(!$this->schedulerConfig->reloadRequired())
			{
				return;
			}
			try
			{
				if(!$this->schedulerConfig->load())
				{
					return;
				}
			}
			catch(Exception $e)
			{
				KalturaLog::alert("Error loading configuration from api servers!!! " . $e->getMessage());
				return;
			}
		}

		KScheduleHelperManager::clearFilters();

		$this->queueSizes = array();

		$configItems = $this->createConfigItem($this->schedulerConfig->toArray());
		$taskConfigs = $this->schedulerConfig->getTaskConfigList();

		$this->logDir = $this->schedulerConfig->getLogDir();
		$this->statusInterval = $this->schedulerConfig->getStatusInterval();
		$this->schedulerStatusInterval = $this->schedulerConfig->getSchedulerStatusInterval();
		KDwhClient::setEnabled($this->schedulerConfig->getDwhEnabled());
		KDwhClient::setFileName($this->schedulerConfig->getDwhPath());
{'fraction_non_alphanumeric': 0.14271781534460337, 'fraction_numerical': 0.0011378413524057217, 'mean_word_length': 3.9027888446215138, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2129098', 'n_tokens_mistral': 2162, 'n_tokens_neox': 1888, 'n_words': 443}