增加端口号参数;对是否允许code在working_subclass间复用设定两种情况

This commit is contained in:
Yu Sun
2022-08-10 14:56:42 +08:00
parent b54c1650cd
commit 54eae08472
4 changed files with 61 additions and 27 deletions

View File

@@ -8,9 +8,24 @@ require_once __DIR__ . '/vendor/autoload.php';
use EdgeManager\EDataCapture\{ EDataCapture, ENodeConfigure };
$options = getopt('h::', ['server_name:', 'user:', 'password:', 'help::']);
$options = getopt('h::', ['no_dup_code', 'server_name:', 'port::', 'user:', 'password:', 'help::']);
init_db($options['server_name'], $options['user'], $options['password']);
if (array_key_exists('h', $options) or array_key_exists('help', $options)) {
print_r(
"EdgeManager使用说明
--no_dup_code 禁止code在不同的working subclass间复用
--server_name pg实例的FQDN
--user pg实例的用户名
--port pg实例的端口号
--password pg实例的密码
-h, --help 显示此帮助信息
"
);
exit;
}
init_db($options['server_name'], $options['port'] ?? 5432, $options['user'], $options['password']);
$worker = new Worker('http://0.0.0.0:8888');
$worker -> name = 'EntryPoint';
@@ -20,8 +35,8 @@ $worker -> onWorkerStart = function(Worker $worker) {
global $options, $dbconn;
$dbconn = pg_connect(sprintf(
"host=%s dbname=scada user=%s password=%s",
$options['server_name'], $options['user'], $options['password']
"host=%s port=%s dbname=scada user=%s password=%s",
$options['server_name'], $options['port'] ?? 5432, $options['user'], $options['password']
));
};
@@ -95,7 +110,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
}
}
} else if ($post -> action === 'set_node_data') {
$data_capture = new EDataCapture($dbconn, post: $post);
$data_capture = new EDataCapture($dbconn, post: $post, no_dup_code: $options['no_dup_code'] ?? true);
if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') {
$response = new Response(200, [
'Content-Type' => 'application/json;charset=utf-8',
@@ -228,8 +243,8 @@ $consumer -> onWorkerStart = function(Worker $consumer) {
global $options, $consumer_dbconn;
$consumer_dbconn = pg_connect(sprintf(
"host=%s dbname=scada user=%s password=%s",
$options['server_name'], $options['user'], $options['password']
"host=%s port=%s dbname=scada user=%s password=%s",
$options['server_name'], $options['port'] ?? 5432, $options['user'], $options['password']
));
};
@@ -239,7 +254,7 @@ $consumer -> onMessage = function(TcpConnection $connection, $task_data) {
$task_data = json_decode($task_data);
if ($task_data -> action === 'add_node') {
$enode_configure = new ENodeConfigure($consumer_dbconn, post: $task_data -> data);
$enode_configure = new ENodeConfigure($consumer_dbconn, post: $task_data -> data, no_dup_code: $options['no_dup_code'] ?? true);
$res = $enode_configure -> add_node();
if ($res === true)
@@ -250,7 +265,7 @@ $consumer -> onMessage = function(TcpConnection $connection, $task_data) {
else if ($res === "REPLICATED")
$connection -> send(json_encode(array(
'code' => 1,
'msg' => '同一工序单元内的节点编码不可重复!'
'msg' => isset($options['no_dup_code']) ? '节点编码不可重复!' : '同一工序单元内的节点编码不可重复!'
)));
else if ($res === false) {
$connection -> send(json_encode(array(