Validate queue driver configuration before saving

This commit is contained in:
Kijin Sung 2024-10-12 01:35:13 +09:00
parent 0ee9747a22
commit 36af489b15
7 changed files with 80 additions and 6 deletions

View file

@ -68,7 +68,7 @@ class Queue extends Base
}
// Validate required and optional driver settings.
$driver_config = array();
$driver_config = [];
foreach ($drivers[$driver]['required'] as $conf_name)
{
$conf_value = trim($vars->{'queue_' . $driver . '_' . $conf_name} ?? '');
@ -105,6 +105,18 @@ class Queue extends Base
throw new Exception('msg_queue_invalid_key');
}
// Validate actual operation of the driver.
$driver_class = '\\Rhymix\\Framework\\Drivers\\Queue\\' . $driver;
if (!class_exists($driver_class) || !$driver_class::isSupported())
{
throw new Exception('msg_queue_driver_not_found');
}
if (!$driver_class::validateConfig($driver_config))
{
throw new Exception('msg_queue_driver_not_usable');
}
// Save system config.
Config::set("queue.enabled", $enabled);
Config::set("queue.driver", $driver);

View file

@ -306,7 +306,8 @@ $lang->msg_queue_instructions['webcron'] = 'Configure an external cron service t
$lang->msg_queue_instructions['systemd1'] = 'Put the following content in <code>/etc/systemd/system/rhymix-queue.service</code>';
$lang->msg_queue_instructions['systemd2'] = 'Put the following content in <code>/etc/systemd/system/rhymix-queue.timer</code>';
$lang->msg_queue_instructions['systemd3'] = 'Execute the following commands to enable the timer, and monitor your journal to make sure that it is operating as scheduled.';
$lang->msg_queue_driver_not_found = 'Invalid task queue driver';
$lang->msg_queue_driver_not_found = 'The selected task queue driver is not supported on this server.';
$lang->msg_queue_driver_not_usable = 'The selected task queue driver failed to initialize using the configuration values you entered.';
$lang->msg_queue_driver_cannot_be_dummy = 'In otder to use the task queue, you must select a driver other than "Not use"';
$lang->msg_queue_invalid_config = 'Missing or invalid configuration for the selected queue driver.';
$lang->msg_queue_invalid_interval = 'The calling interval must be between 1 and 10 minutes.';

View file

@ -302,7 +302,8 @@ $lang->msg_queue_instructions['webcron'] = '아래의 URL을 1분 간격 또는
$lang->msg_queue_instructions['systemd1'] = '<code>/etc/systemd/system/rhymix-queue.service</code> 파일에 아래와 같은 내용을 넣습니다.';
$lang->msg_queue_instructions['systemd2'] = '<code>/etc/systemd/system/rhymix-queue.timer</code> 파일에 아래와 같은 내용을 넣습니다.';
$lang->msg_queue_instructions['systemd3'] = '아래의 명령을 실행하여 타이머를 활성화하고, 정상 작동하는지 모니터링하십시오.';
$lang->msg_queue_driver_not_found = '지원하지 않는 비동기 드라이버입니다.';
$lang->msg_queue_driver_not_found = '이 서버에서 지원하지 않는 비동기 드라이버입니다.';
$lang->msg_queue_driver_not_usable = '입력하신 정보로 비동기 드라이버와 연동하는 데 실패했습니다. 드라이버 설정을 확인해 주십시오.';
$lang->msg_queue_driver_cannot_be_dummy = '비동기 작업을 사용하려면 "미사용" 이외의 드라이버를 선택해야 합니다.';
$lang->msg_queue_invalid_config = '비동기 드라이버의 필수 설정이 누락되었습니다.';
$lang->msg_queue_invalid_interval = '호출 간격은 1~10분 이내여야 합니다.';