Manager::checkAgent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Manager
  4. checkAgent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/recurring/manager.php
  • Класс: Bitrix\Crm\Recurring\Manager
  • Вызов: Manager::checkAgent
static function checkAgent()
{
	$agentNames = array();
	$listActive = array();

	$entities = self::getEntityTypeList();
	foreach ($entities as $typeEntity)
	{
		if (self::isAllowedExpose($typeEntity))
		{
			$agentNames[$typeEntity] = "\\".__CLASS__."::exposeAgent('".$typeEntity."');";
		}
	}

	if (empty($agentNames))
	{
		return '';
	}

	$agentData = \CAgent::GetList(
		array("ID"=>"DESC"),
		array(
			"MODULE_ID" => "crm",
			"NAME" => "\\".__CLASS__."::exposeAgent(%"
		)
	);

	while ($agent = $agentData->Fetch())
	{
		if ($agent['LAST_EXEC'] < $agent['NEXT_EXEC'])
		{
			$listActive[$agent['NAME']] = $agent['ID'];
		}
		else
		{
			\CAgent::Delete($agent['ID']);
		}
	}

	foreach ($agentNames as $name)
	{
		if (empty($listActive[$name]))
		{
			\CAgent::AddAgent($name, "crm", "N", 180, "", "Y");
		}
	}

	$currentAgentData = \CAgent::GetList(
		array(),
		array(
			"MODULE_ID" => "crm",
			"NAME" => "\\".__CLASS__."::checkAgent(%"
		)
	);

	if ($currentAgent = $currentAgentData->Fetch())
	{
		\CAgent::Delete($currentAgent['ID']);
		$nextCheckDate = DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00'));
		\CAgent::AddAgent("\\".__CLASS__."::checkAgent();", "crm", "N", 86400, "", "Y", $nextCheckDate->toString());
	}

	return '';
}

Добавить комментарий