mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-06 18:21:39 +09:00
Merge pull request #2414 from kijin/pr/queue
비동기 처리를 위한 간단한 Queue 기능 #2402
This commit is contained in:
commit
e39c3bedd1
19 changed files with 1450 additions and 0 deletions
|
|
@ -34,6 +34,8 @@
|
|||
<action name="procAdminUpdateDebug" class="Controllers\SystemConfig\Debug" />
|
||||
<action name="dispAdminConfigSEO" class="Controllers\SystemConfig\SEO" menu_name="adminConfigurationGeneral" />
|
||||
<action name="procAdminUpdateSEO" class="Controllers\SystemConfig\SEO" />
|
||||
<action name="dispAdminConfigQueue" class="Controllers\SystemConfig\Queue" menu_name="adminConfigurationGeneral" />
|
||||
<action name="procAdminUpdateQueue" class="Controllers\SystemConfig\Queue" />
|
||||
<action name="dispAdminConfigSitelock" class="Controllers\SystemConfig\SiteLock" menu_name="adminConfigurationGeneral" />
|
||||
<action name="procAdminUpdateSitelock" class="Controllers\SystemConfig\SiteLock" />
|
||||
<!-- Admin Interface Config -->
|
||||
|
|
|
|||
135
modules/admin/controllers/systemconfig/Queue.php
Normal file
135
modules/admin/controllers/systemconfig/Queue.php
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Modules\Admin\Controllers\SystemConfig;
|
||||
|
||||
use Context;
|
||||
use Rhymix\Framework\Config;
|
||||
use Rhymix\Framework\Exception;
|
||||
use Rhymix\Framework\Queue as RFQueue;
|
||||
use Rhymix\Framework\Security;
|
||||
use Rhymix\Modules\Admin\Controllers\Base;
|
||||
|
||||
class Queue extends Base
|
||||
{
|
||||
/**
|
||||
* Display Notification Settings page
|
||||
*/
|
||||
public function dispAdminConfigQueue()
|
||||
{
|
||||
// Load queue drivers.
|
||||
$queue_drivers = RFQueue::getSupportedDrivers();
|
||||
uasort($queue_drivers, function($a, $b) {
|
||||
if ($a['name'] === 'Dummy') return -1;
|
||||
if ($b['name'] === 'Dummy') return 1;
|
||||
return strnatcasecmp($a['name'], $b['name']);
|
||||
});
|
||||
Context::set('queue_drivers', $queue_drivers);
|
||||
Context::set('queue_driver', config('queue.driver') ?: 'dummy');
|
||||
|
||||
// Set the default auth key.
|
||||
if (!config('queue.key'))
|
||||
{
|
||||
config('queue.key', Security::getRandom(32));
|
||||
}
|
||||
|
||||
// Set defaults for Redis.
|
||||
if (!config('queue.redis'))
|
||||
{
|
||||
config('queue.redis', [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '6379',
|
||||
'dbnum' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->setTemplateFile('config_queue');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update notification configuration.
|
||||
*/
|
||||
public function procAdminUpdateQueue()
|
||||
{
|
||||
$vars = Context::getRequestVars();
|
||||
|
||||
// Enabled?
|
||||
$enabled = $vars->queue_enabled === 'Y';
|
||||
|
||||
// Validate the driver.
|
||||
$drivers = RFQueue::getSupportedDrivers();
|
||||
$driver = trim($vars->queue_driver);
|
||||
if (!array_key_exists($driver, $drivers))
|
||||
{
|
||||
throw new Exception('msg_queue_driver_not_found');
|
||||
}
|
||||
if ($enabled && (!$driver || $driver === 'dummy'))
|
||||
{
|
||||
throw new Exception('msg_queue_driver_cannot_be_dummy');
|
||||
}
|
||||
|
||||
// Validate required and optional driver settings.
|
||||
$driver_config = [];
|
||||
foreach ($drivers[$driver]['required'] as $conf_name)
|
||||
{
|
||||
$conf_value = trim($vars->{'queue_' . $driver . '_' . $conf_name} ?? '');
|
||||
if ($conf_value === '')
|
||||
{
|
||||
throw new Exception('msg_queue_invalid_config');
|
||||
}
|
||||
$driver_config[$conf_name] = $conf_value === '' ? null : $conf_value;
|
||||
}
|
||||
foreach ($drivers[$driver]['optional'] as $conf_name)
|
||||
{
|
||||
$conf_value = trim($vars->{'queue_' . $driver . '_' . $conf_name} ?? '');
|
||||
$driver_config[$conf_name] = $conf_value === '' ? null : $conf_value;
|
||||
}
|
||||
|
||||
// Validate the interval.
|
||||
$interval = intval($vars->queue_interval ?? 1);
|
||||
if ($interval < 1 || $interval > 10)
|
||||
{
|
||||
throw new Exception('msg_queue_invalid_interval');
|
||||
}
|
||||
|
||||
// Validate the process count.
|
||||
$process_count = intval($vars->queue_process_count ?? 1);
|
||||
if ($process_count < 1 || $process_count > 10)
|
||||
{
|
||||
throw new Exception('msg_queue_invalid_process_count');
|
||||
}
|
||||
|
||||
// Validate the key.
|
||||
$key = trim($vars->queue_key ?? '');
|
||||
if (strlen($key) < 16 || !ctype_alnum($key))
|
||||
{
|
||||
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);
|
||||
Config::set("queue.interval", $interval);
|
||||
Config::set("queue.process_count", $process_count);
|
||||
Config::set("queue.key", $key);
|
||||
Config::set("queue.$driver", $driver_config);
|
||||
if (!Config::save())
|
||||
{
|
||||
throw new Exception('msg_failed_to_save_config');
|
||||
}
|
||||
|
||||
$this->setMessage('success_updated');
|
||||
$this->setRedirectUrl(Context::get('success_return_url') ?: getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminConfigQueue'));
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ $lang->subtitle_security = 'Security';
|
|||
$lang->subtitle_advanced = 'Advanced';
|
||||
$lang->subtitle_domains = 'Domains';
|
||||
$lang->subtitle_debug = 'Debug';
|
||||
$lang->subtitle_queue = 'Async Queue';
|
||||
$lang->subtitle_seo = 'SEO Settings';
|
||||
$lang->subtitle_etc = 'Other Settings';
|
||||
$lang->current_state = 'Current state';
|
||||
|
|
@ -282,6 +283,36 @@ $lang->og_extract_images_fallback = 'Use site default image only';
|
|||
$lang->og_extract_hashtags = 'Extract Hashtags from Document';
|
||||
$lang->og_use_nick_name = 'Include Author Name';
|
||||
$lang->og_use_timestamps = 'Include Timestamps';
|
||||
$lang->cmd_queue_description = 'Improve response times by processing time-consuming tasks, such as sending notifications, asynchronously.<br>This is an experimental feature. It may not be stable depending on your hosting environment.';
|
||||
$lang->cmd_queue_enabled = 'Use Task Queue';
|
||||
$lang->cmd_queue_enabled_help = 'The task queue will stop accepting new tasks if you uncheck the above.';
|
||||
$lang->cmd_queue_driver = 'Queue Driver';
|
||||
$lang->cmd_queue_driver_help = 'Select the driver for the task queue that suits your hosting environment and website needs.<br>Some drivers such as Redis will need the corresponding program to be installed on the server.';
|
||||
$lang->cmd_queue_interval = 'Calling Interval';
|
||||
$lang->cmd_queue_interval_help = 'Use a scheduler such as crontab or systemd timer to call the script on a set interval.<br>All tasks are processed as soon as possible regardless of the interval, but a short interval means quick recovery from any error.<br>For web-based cron, this should not exceed the max_execution_time setting in php.ini.<br>The max_execution_time on this server is %d seconds.';
|
||||
$lang->cmd_queue_process_count = 'Process Count';
|
||||
$lang->cmd_queue_process_count_help = 'Use multiple processes to increase throughput. This may increase server load significantly.<br>Keep a value of 1 unless you have a high-performance dedicated server.<br>Multiprocessing is not supported when using web-based cron.';
|
||||
$lang->cmd_queue_call_script = 'Processing Script';
|
||||
$lang->cmd_queue_webcron_key = 'Webcron Auth Key';
|
||||
$lang->cmd_queue_config_keys['host'] = 'Host';
|
||||
$lang->cmd_queue_config_keys['port'] = 'Port';
|
||||
$lang->cmd_queue_config_keys['user'] = 'User';
|
||||
$lang->cmd_queue_config_keys['pass'] = 'Password';
|
||||
$lang->cmd_queue_config_keys['dbnum'] = 'DB Number';
|
||||
$lang->msg_queue_instructions['same_as_php'] = '(same as PHP)';
|
||||
$lang->msg_queue_instructions['crontab1'] = 'Log into the server as the <code>%s</code> account and run <code>crontab -e</code> to paste the following content into your crontab. (DO NOT run it as root!)<br>The <code>%s</code> directory in the example should be replaced with a path where logs can be recorded.';
|
||||
$lang->msg_queue_instructions['crontab2'] = 'If you change the calling interval below, the crontab interval must be adjusted accordingly.';
|
||||
$lang->msg_queue_instructions['webcron'] = 'Configure an external cron service to make a GET request to the following URL every minute, or following the interval set below.<br>Check your logs to make sure that the cron service is reaching your website.';
|
||||
$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 = '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.';
|
||||
$lang->msg_queue_invalid_process_count = 'The process count must be between 1 and 10.';
|
||||
$lang->msg_queue_invalid_key = 'The webcron auth key must be at least 16 characters long, and only consist of alphanumeric characters.';
|
||||
$lang->autoinstall = 'EasyInstall';
|
||||
$lang->last_week = 'Last Week';
|
||||
$lang->this_week = 'This Week';
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ $lang->subtitle_notification = '알림 설정';
|
|||
$lang->subtitle_security = '보안 설정';
|
||||
$lang->subtitle_advanced = '고급 설정';
|
||||
$lang->subtitle_debug = '디버그 설정';
|
||||
$lang->subtitle_queue = '비동기 작업';
|
||||
$lang->subtitle_seo = 'SEO 설정';
|
||||
$lang->subtitle_etc = '기타';
|
||||
$lang->current_state = '현황';
|
||||
|
|
@ -278,6 +279,36 @@ $lang->og_extract_images_fallback = '사이트 대표 이미지 사용';
|
|||
$lang->og_extract_hashtags = '본문에서 해시태그 추출';
|
||||
$lang->og_use_nick_name = '글 작성자 이름 표시';
|
||||
$lang->og_use_timestamps = '글 작성/수정 시각 표시';
|
||||
$lang->cmd_queue_description = '메일 발송, 푸시알림 등 시간이 오래 걸리거나 외부 서비스와 연동하는 작업을 비동기 처리하여 응답 속도를 개선합니다.<br>실험적인 기능입니다. 호스팅 환경에 따라서는 안정적으로 작동하지 않을 수도 있습니다.';
|
||||
$lang->cmd_queue_enabled = '비동기 작업 사용';
|
||||
$lang->cmd_queue_enabled_help = '체크를 해제하면 더이상 작업을 접수하지 않습니다.';
|
||||
$lang->cmd_queue_driver = '비동기 드라이버';
|
||||
$lang->cmd_queue_driver_help = '비동기 작업을 관리할 방법을 설정합니다. 호스팅 환경과 사이트의 필요에 맞추어 선택하세요.<br>Redis 등 일부 드라이버는 서버에 해당 기능이 설치되어 있어야 사용할 수 있습니다.';
|
||||
$lang->cmd_queue_interval = '호출 간격';
|
||||
$lang->cmd_queue_interval_help = 'crontab, systemd timer, 웹크론 등을 사용하여 일정한 주기로 스크립트를 호출해 주십시오.<br>모든 비동기 작업은 호출 간격과 무관하게 실시간으로 처리되나, 호출 간격이 짧으면 장애 발생시 신속하게 복구됩니다.<br>웹크론 사용시에는 php.ini의 실행 시간 제한을 초과하지 않는 것이 좋습니다.<br>이 서버의 max_execution_time은 %d초로 설정되어 있습니다.';
|
||||
$lang->cmd_queue_process_count = '프로세스 갯수';
|
||||
$lang->cmd_queue_process_count_help = '여러 개의 프로세스를 동시에 실행하여 처리 용량을 늘립니다. 서버 부하가 증가할 수 있습니다.<br>고성능 단독서버가 아니라면 1을 유지하시기 바랍니다.<br>웹크론으로 호출한 경우에는 멀티프로세싱을 지원하지 않습니다.';
|
||||
$lang->cmd_queue_call_script = '작업 처리 스크립트';
|
||||
$lang->cmd_queue_webcron_key = '웹크론 인증키';
|
||||
$lang->cmd_queue_config_keys['host'] = '호스트';
|
||||
$lang->cmd_queue_config_keys['port'] = '포트';
|
||||
$lang->cmd_queue_config_keys['user'] = '아이디';
|
||||
$lang->cmd_queue_config_keys['pass'] = '암호';
|
||||
$lang->cmd_queue_config_keys['dbnum'] = 'DB 번호';
|
||||
$lang->msg_queue_instructions['same_as_php'] = 'PHP를 실행하는 계정과 동일한';
|
||||
$lang->msg_queue_instructions['crontab1'] = '%s 계정으로 서버에 로그인하여 <code>crontab -e</code> 명령을 실행한 후, 아래의 내용을 붙여넣으십시오. (root 권한으로 실행하지 마십시오.)<br>예제의 <code>%s</code> 디렉토리는 로그를 기록할 수 있는 경로로 변경하여 사용하십시오.';
|
||||
$lang->msg_queue_instructions['crontab2'] = '스크립트 호출 간격을 변경할 경우, 설정에 맞추어 crontab 실행 간격도 조절하여야 합니다.';
|
||||
$lang->msg_queue_instructions['webcron'] = '아래의 URL을 1분 간격 또는 아래에서 설정한 호출 간격에 맞추어 GET으로 호출하도록 합니다.<br>웹크론 서비스가 방화벽이나 CDN 등에 의해 차단되지 않도록 주의하고, 정상적으로 호출되는지 서버 로그를 확인하십시오.';
|
||||
$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_usable = '입력하신 정보로 비동기 드라이버와 연동하는 데 실패했습니다. 드라이버 설정을 확인해 주십시오.';
|
||||
$lang->msg_queue_driver_cannot_be_dummy = '비동기 작업을 사용하려면 "미사용" 이외의 드라이버를 선택해야 합니다.';
|
||||
$lang->msg_queue_invalid_config = '비동기 드라이버의 필수 설정이 누락되었습니다.';
|
||||
$lang->msg_queue_invalid_interval = '호출 간격은 1~10분 이내여야 합니다.';
|
||||
$lang->msg_queue_invalid_process_count = '프로세스 갯수는 1~10개 이내여야 합니다.';
|
||||
$lang->msg_queue_invalid_key = '웹크론 인증키는 16자 이상으로, 알파벳 대소문자와 숫자만으로 이루어져야 합니다.';
|
||||
$lang->autoinstall = '쉬운 설치';
|
||||
$lang->last_week = '지난주';
|
||||
$lang->this_week = '이번주';
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@
|
|||
<li class="x_active"|cond="$act == 'dispAdminConfigAdvanced'"><a href="{getUrl('', 'module', 'admin', 'act', 'dispAdminConfigAdvanced')}">{$lang->subtitle_advanced}</a></li>
|
||||
<li class="x_active"|cond="$act == 'dispAdminConfigDebug'"><a href="{getUrl('', 'module', 'admin', 'act', 'dispAdminConfigDebug')}">{$lang->subtitle_debug}</a></li>
|
||||
<li class="x_active"|cond="$act == 'dispAdminConfigSEO'"><a href="{getUrl('', 'module', 'admin', 'act', 'dispAdminConfigSEO')}">{$lang->subtitle_seo}</a></li>
|
||||
<li class="x_active"|cond="$act == 'dispAdminConfigQueue'"><a href="{getUrl('', 'module', 'admin', 'act', 'dispAdminConfigQueue')}">{$lang->subtitle_queue}</a></li>
|
||||
<li class="x_active"|cond="$act == 'dispAdminConfigSitelock'"><a href="{getUrl('', 'module', 'admin', 'act', 'dispAdminConfigSitelock')}">{$lang->subtitle_sitelock}</a></li>
|
||||
</ul>
|
||||
|
|
|
|||
195
modules/admin/tpl/config_queue.html
Normal file
195
modules/admin/tpl/config_queue.html
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<config autoescape="on" />
|
||||
|
||||
<include target="config_header.html" />
|
||||
<load target="css/queue_config.scss" />
|
||||
<load target="js/queue_config.js" />
|
||||
|
||||
<div class="message">
|
||||
<p>{$lang->cmd_queue_description}</p>
|
||||
</div>
|
||||
|
||||
<div cond="!empty($XE_VALIDATOR_MESSAGE) && $XE_VALIDATOR_ID == 'modules/admin/tpl/config_queue/1'" class="message {$XE_VALIDATOR_MESSAGE_TYPE}">
|
||||
<p>{$XE_VALIDATOR_MESSAGE}</p>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var queue_drivers = {json_encode($queue_drivers)|noescape};
|
||||
</script>
|
||||
|
||||
<form action="./" method="post" class="x_form-horizontal">
|
||||
<input type="hidden" name="module" value="admin" />
|
||||
<input type="hidden" name="act" value="procAdminUpdateQueue" />
|
||||
<input type="hidden" name="xe_validator_id" value="modules/admin/tpl/config_queue/1" />
|
||||
|
||||
<section class="section">
|
||||
|
||||
<h2>{$lang->subtitle_queue}</h2>
|
||||
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->cmd_queue_enabled}</label>
|
||||
<div class="x_controls">
|
||||
<label for="queue_enabled" class="x_inline">
|
||||
<input type="checkbox" name="queue_enabled" id="queue_enabled" value="Y" checked="checked"|cond="config('queue.enabled')" />
|
||||
{$lang->cmd_queue_enabled}
|
||||
</label>
|
||||
<br>
|
||||
<p class="x_help-block">{$lang->cmd_queue_enabled_help}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="queue_driver">{$lang->cmd_queue_driver}</label>
|
||||
<div class="x_controls">
|
||||
<select name="queue_driver" id="queue_driver">
|
||||
<!--@foreach($queue_drivers as $driver_name => $driver_definition)-->
|
||||
<option value="{$driver_name}" selected="selected"|cond="$queue_driver === $driver_name">{$driver_name === 'dummy' ? $lang->notuse : $driver_definition['name']}</option>
|
||||
<!--@end-->
|
||||
</select>
|
||||
<p class="x_help-block">{$lang->cmd_queue_driver_help}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--@foreach($queue_drivers as $driver_name => $driver_definition)-->
|
||||
|
||||
{@ $conf_names = array_merge($driver_definition['required'], $driver_definition['optional'])}
|
||||
|
||||
<!--@foreach($conf_names as $conf_name)-->
|
||||
|
||||
{@ $conf_value = escape(config("queue.$driver_name.$conf_name"))}
|
||||
{@ $text_keys = ['host', 'user']}
|
||||
{@ $number_keys = ['port', 'dbnum']}
|
||||
{@ $password_keys = ['pass']}
|
||||
|
||||
<!--@if(in_array($conf_name, $text_keys))-->
|
||||
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
||||
<label class="x_control-label" for="queue_{$driver_name}_{$conf_name}">{$lang->cmd_queue_config_keys[$conf_name]}</label>
|
||||
<div class="x_controls">
|
||||
<input type="text" name="queue_{$driver_name}_{$conf_name}" id="queue_{$driver_name}_{$conf_name}" value="{$conf_value}" />
|
||||
</div>
|
||||
</div>
|
||||
<!--@end-->
|
||||
|
||||
<!--@if(in_array($conf_name, $number_keys))-->
|
||||
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
||||
<label class="x_control-label" for="queue_{$driver_name}_{$conf_name}">{$lang->cmd_queue_config_keys[$conf_name]}</label>
|
||||
<div class="x_controls">
|
||||
<input type="number" name="queue_{$driver_name}_{$conf_name}" id="queue_{$driver_name}_{$conf_name}" value="{$conf_value}" />
|
||||
</div>
|
||||
</div>
|
||||
<!--@end-->
|
||||
|
||||
<!--@if(in_array($conf_name, $password_keys))-->
|
||||
<div class="x_control-group hidden-by-default show-for-{$driver_name}">
|
||||
<label class="x_control-label" for="queue_{$driver_name}_{$conf_name}">{$lang->cmd_queue_config_keys[$conf_name]}</label>
|
||||
<div class="x_controls">
|
||||
<input type="password" name="queue_{$driver_name}_{$conf_name}" id="queue_{$driver_name}_{$conf_name}" value="{$conf_value}" autocomplete="new-password" />
|
||||
</div>
|
||||
</div>
|
||||
<!--@end-->
|
||||
|
||||
<!--@end-->
|
||||
|
||||
<!--@end-->
|
||||
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
<h2>{$lang->cmd_queue_call_script}</h2>
|
||||
|
||||
<div class="queue-script-setup">
|
||||
<ul class="qss-tabs x_nav x_nav-tabs">
|
||||
<li class="x_active"><a href="#" data-value="crontab">crontab</a></li>
|
||||
<li><a href="#" data-value="webcron">webcron</a></li>
|
||||
<li><a href="#" data-value="systemd-timer">systemd timer</a></li>
|
||||
</ul>
|
||||
<div class="qss-content crontab active">
|
||||
{@
|
||||
if (function_exists('posix_getpwuid') && function_exists('posix_getuid')):
|
||||
$user_info = posix_getpwuid(posix_getuid());
|
||||
if (!empty($user_info['dir'])):
|
||||
$user_info['dir'] .= DIRECTORY_SEPARATOR;
|
||||
endif;
|
||||
else:
|
||||
$user_info = [];
|
||||
$user_info['name'] = $lang->msg_queue_instructions['same_as_php'];
|
||||
endif;
|
||||
}
|
||||
<p class="qss-instruction">
|
||||
{sprintf($lang->msg_queue_instructions['crontab1'], $user_info['name'] ?? 'PHP', $user_info['dir'] . 'logs')|noescape}
|
||||
</p>
|
||||
<pre><code>* * * * * php {\RX_BASEDIR}index.php common.cron >> {$user_info['dir']}logs{\DIRECTORY_SEPARATOR}queue.log 2>&1</code></pre>
|
||||
<p class="qss-instruction">
|
||||
{$lang->msg_queue_instructions['crontab2']|noescape}
|
||||
</p>
|
||||
</div>
|
||||
<div class="qss-content webcron">
|
||||
<p class="qss-instruction">
|
||||
{$lang->msg_queue_instructions['webcron']|noescape}
|
||||
</p>
|
||||
<pre><code class="webcron-url">{getFullUrl('')}common/scripts/cron.php?key={config('queue.key')}</code></pre>
|
||||
</div>
|
||||
<div class="qss-content systemd-timer">
|
||||
<p class="qss-instruction">
|
||||
{$lang->msg_queue_instructions['systemd1']|noescape}
|
||||
</p>
|
||||
<pre><code>[Unit]
|
||||
Description=Rhymix Queue Service
|
||||
|
||||
[Service]
|
||||
ExecStart=php {\RX_BASEDIR}index.php common.cron
|
||||
User={$user_info['name']}</code></pre>
|
||||
<p class="qss-instruction">
|
||||
{$lang->msg_queue_instructions['systemd2']|noescape}
|
||||
</p>
|
||||
<pre><code>[Unit]
|
||||
Description=Rhymix Queue Timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:*:00
|
||||
Unit=rhymix-queue.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target</code></pre>
|
||||
<p class="qss-instruction">
|
||||
{$lang->msg_queue_instructions['systemd3']|noescape}
|
||||
</p>
|
||||
<pre><code>systemctl daemon-reload
|
||||
systemctl start rhymix-queue.timer
|
||||
systemctl enable rhymix-queue.timer</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="queue_key">{$lang->cmd_queue_webcron_key}</label>
|
||||
<div class="x_controls">
|
||||
<input type="text" class="x_full-width" name="queue_key" id="queue_key" value="{config('queue.key')}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="queue_interval">{$lang->cmd_queue_interval}</label>
|
||||
<div class="x_controls">
|
||||
<input type="number" name="queue_interval" id="queue_interval" min="1" max="10" value="{config('queue.interval') ?: 1}" />
|
||||
<span class="x_inline">{$lang->unit_min}</span>
|
||||
<br>
|
||||
<p class="x_help-block" style="margin-top:10px">{sprintf($lang->cmd_queue_interval_help, ini_get('max_execution_time'))|noescape}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="queue_process_count">{$lang->cmd_queue_process_count}</label>
|
||||
<div class="x_controls">
|
||||
<input type="number" name="queue_process_count" id="queue_process_count" min="1" max="10" value="{config('queue.process_count') ?: 1}" />
|
||||
<p class="x_help-block">{$lang->cmd_queue_process_count_help}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<div class="x_clearfix btnArea">
|
||||
<div class="x_pull-right">
|
||||
<button type="submit" class="x_btn x_btn-primary">{$lang->cmd_save}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
27
modules/admin/tpl/css/queue_config.scss
Normal file
27
modules/admin/tpl/css/queue_config.scss
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
.queue-script-setup {
|
||||
.qss-content {
|
||||
display: none;
|
||||
&.active {
|
||||
display: block;
|
||||
border: 1px solid #ddd;
|
||||
border-top: 0;
|
||||
margin-top: -20px;
|
||||
padding: 20px 12px 10px 12px;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.qss-instruction {
|
||||
margin-bottom: 10px;
|
||||
code {
|
||||
color: #333;
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
padding: 0 1px;
|
||||
}
|
||||
}
|
||||
.pre {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
modules/admin/tpl/js/queue_config.js
Normal file
33
modules/admin/tpl/js/queue_config.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(function($) {
|
||||
$(function() {
|
||||
|
||||
$("#queue_driver").on("change", function() {
|
||||
const selected_driver = $(this).val();
|
||||
$(this).parents("section").find("div.x_control-group.hidden-by-default, p.x_help-block.hidden-by-default").each(function() {
|
||||
if ($(this).hasClass("show-for-" + selected_driver)) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
}).triggerHandler("change");
|
||||
|
||||
$("#queue_key").on('change keyup paste', function() {
|
||||
const key = encodeURIComponent(String($(this).val()));
|
||||
$('.webcron-url').text($('.webcron-url').text().replace(/\?key=[a-zA-Z0-9]+/g, '?key=' + key));
|
||||
});
|
||||
|
||||
const qss = $('.queue-script-setup');
|
||||
const qss_tabs = qss.find('.qss-tabs');
|
||||
const qss_content = qss.find('.qss-content');
|
||||
qss_tabs.on('click', 'a', function(event) {
|
||||
const selected_tab = $(this).data('value');
|
||||
qss_tabs.find('li').removeClass('x_active');
|
||||
$(this).parent().addClass('x_active');
|
||||
qss_content.removeClass('active');
|
||||
qss_content.filter('.' + selected_tab).addClass('active');
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
7
modules/module/schemas/task_queue.xml
Normal file
7
modules/module/schemas/task_queue.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<table name="task_queue">
|
||||
<column name="id" type="bigint" notnull="notnull" primary_key="primary_key" auto_increment="auto_increment" />
|
||||
<column name="handler" type="varchar" size="191" notnull="notnull" />
|
||||
<column name="args" type="longtext" notnull="notnull" />
|
||||
<column name="options" type="longtext" notnull="notnull" />
|
||||
<column name="regdate" type="datetime" notnull="notnull" default="current_timestamp()" index="idx_regdate" />
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue