Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/yandex.market/lib/trading/procedure/ |
Upload File : |
<?php namespace Yandex\Market\Trading\Procedure; use Yandex\Market; use Bitrix\Main; class Runner { /** @var string */ protected $entityType; /** @var string */ protected $entityId; /** @var string|null*/ protected $auditType; /** @var array|null*/ protected $lastRun; /** @var Market\Psr\Log\LoggerInterface*/ protected $logger; public function __construct($entityType, $entityId) { $this->entityType = $entityType; $this->entityId = $entityId; } public function run(Market\Trading\Setup\Model $setup, $path, $data) { $this->saveLastRun($setup, $path, $data); $service = $setup->wakeupService(); $environment = $setup->getEnvironment(); $router = $service->getRouter(); $this->setLogger($service->getLogger()); if (!$setup->isActive()) { throw new Main\SystemException('trading platform is inactive'); } $action = $router->getDataAction($path, $environment, $data); $this->setAuditType($action->getAudit()); $action->process(); return $action->getResponse(); } public function clearRepeat() { if ($this->lastRun === null) { throw new Main\ObjectNotFoundException(); } QueueTable::deleteBatch([ 'filter' => [ '=CAMPAIGN_ID' => $this->lastRun['CAMPAIGN_ID'], '=PATH' => $this->lastRun['PATH'], '=ENTITY_TYPE' => $this->entityType, '=ENTITY_ID' => $this->entityId, ], ]); } public function createRepeat($interval = 600) { if ($this->lastRun === null) { throw new Main\ObjectNotFoundException(); } QueueTable::add($this->lastRun + [ 'INTERVAL' => $interval, 'ENTITY_TYPE' => $this->entityType, 'ENTITY_ID' => $this->entityId, 'EXEC_DATE' => new Main\Type\DateTime(), 'EXEC_COUNT' => 0 ]); $this->registerRepeatAgent(); } protected function registerRepeatAgent() { Agent::register([ 'method' => 'repeat', 'next_exec' => new Main\Type\DateTime(), ]); } protected function setAuditType($auditType) { $this->auditType = $auditType; } protected function getAuditType() { return $this->auditType ?: Market\Logger\Trading\Audit::PROCEDURE; } protected function setLogger(Market\Psr\Log\LoggerInterface $logger) { $this->logger = $logger; } public function logException(\Exception $exception) { if ($this->logger !== null) { $this->logger->error($exception, [ 'AUDIT' => $this->getAuditType(), 'ENTITY_TYPE' => $this->entityType, 'ENTITY_ID' => $this->entityId, ]); } } protected function saveLastRun(Market\Trading\Setup\Model $setup, $path, $data) { $this->lastRun = [ 'CAMPAIGN_ID' => $setup->getCampaignId(), 'PATH' => $path, 'DATA' => $data, ]; } }