configuring process timeout
This commit is contained in:
parent
b8c160dea4
commit
00954ef640
4 changed files with 33 additions and 5 deletions
|
@ -56,6 +56,7 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('messenger')
|
||||
->children()
|
||||
->scalarNode('message_handler')->isRequired()->defaultValue('simple_console_runner')->end()
|
||||
->scalarNode('process_timeout')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
|
|
|
@ -55,6 +55,13 @@ class RetailCrmServiceExtension extends Extension
|
|||
$config['messenger']['message_handler']
|
||||
);
|
||||
|
||||
if (isset($config['messenger']['process_timeout'])) {
|
||||
$container->setParameter(
|
||||
'retail_crm_service.messenger.process_timeout',
|
||||
$config['messenger']['process_timeout']
|
||||
);
|
||||
}
|
||||
|
||||
$container
|
||||
->register(SymfonySerializerAdapter::class)
|
||||
->setAutowired(true);
|
||||
|
@ -102,8 +109,13 @@ class RetailCrmServiceExtension extends Extension
|
|||
->setAutowired(true);
|
||||
$container->setAlias('simple_console_runner', MessageHandler\SimpleConsoleRunner::class);
|
||||
|
||||
$timeout = $container->hasParameter('retail_crm_service.messenger.process_timeout')
|
||||
? $container->getParameter('retail_crm_service.messenger.process_timeout')
|
||||
: null;
|
||||
|
||||
$container
|
||||
->register(MessageHandler\InNewProcessRunner::class)
|
||||
->setArgument('$timeout', $timeout)
|
||||
->setAutowired(true);
|
||||
$container->setAlias('in_new_process_runner', MessageHandler\InNewProcessRunner::class);
|
||||
|
||||
|
|
|
@ -29,16 +29,29 @@ class InNewProcessRunner implements JobRunner
|
|||
*/
|
||||
private $kernel;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $timeout = self::DEFAULT_TIMEOUT;
|
||||
|
||||
/**
|
||||
* CommandQueueHandler constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
* @param KernelInterface $kernel
|
||||
* @param int|null $timeout
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger, KernelInterface $kernel)
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
KernelInterface $kernel,
|
||||
?int $timeout = null
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->kernel = $kernel;
|
||||
|
||||
if (null !== $timeout) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +76,7 @@ class InNewProcessRunner implements JobRunner
|
|||
|
||||
try {
|
||||
$process
|
||||
->setTimeout(static::DEFAULT_TIMEOUT)
|
||||
->setTimeout($this->timeout)
|
||||
->run(static function(string $type, string $buffer) {
|
||||
echo $buffer;
|
||||
})
|
||||
|
|
|
@ -34,7 +34,8 @@ class ConfigurationTest extends TestCase
|
|||
'type2'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'messenger' => []
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -71,7 +72,8 @@ class ConfigurationTest extends TestCase
|
|||
'type',
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'messenger' => []
|
||||
]
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue