sbusr 文档

说明文档

自述

CI 状态

master :

https://travis-ci.org/Hesong-OpenSource/sbusr.svg?branch=master

develop :

https://travis-ci.org/Hesong-OpenSource/sbusr.svg?branch=develop

如果看不见图片,请直接访问 https://travis-ci.org/Hesong-OpenSource/sbusr 查看构建状态。

介绍

sbusr 读作 s-bus-ser (IPA: sbʌsə),是 和声 IPSC 的远程方法提供程序。

sbusr 使用 IPSC 的 smartbus 与之进行通信,为其提供可扩展的 JSON PRC 远程方法,以实现诸如执行SQL语句、存储过程,进行 WebService 访问等在流程中难以实现的功能。

开发者可自行编写 sbusr 的 RPC 方法,为 IPSC 提供各种不同的扩展功能。

IPSC 流程需要特殊的节点或者自定义函数,通过SmartBus以及相应的插件访问 sbusr

如何运行 sbusr

1 准备运行环境
1.1 支持的操作系统
  • Linux
  • Windows
1.2 安装 Python

sbusr 使用 Python 语言实现的,因此我们首先需要安装 Python。 如果您的操作系统已经配备了版本足够高的 Python ,请忽略本步骤。

访问 https://www.python.org/downloads/ 下载并安装合适的版本。建议使用最新的 Python3 发布版。

由于我们在接下来的步骤中,需要使用 PyPI 包管理器安装 sbusr 所依赖的第三方包,所以在安装Python之后,请安装支持 PyPI 的包管理器。推荐使用 pip

Python3.4以及以上版本已经在标准库中包含了 pip ,不用另行安装。

sbusr 在 python3.4+ 下可以成功运行。

应该可以在 Python2.7+,以及 Python3.x 环境下运行,不过未经测试。

据信可以在 PyPy/Jython/IronPython 下运行,不过未经测试。

1.3 安装Python虚拟环境

这是一个可选步骤。

本文中,我们倾向于在一个Python虚拟环境中安装该程序的依赖包。如果您希望将该程序的依赖包安装到系统全局的Python包集合中,可忽略该步骤。

Python3.4 以及以上版本已经在标准库中包含了虚拟环境 venv ,低版本的 Python 则需要另行安装 virtualenv 。如果已经配置好了 pip ,可使用以下命名安装 virtualenv

pip install virtualenv
2 获取源代码

可通过以下途径获取源代码:

2.1.1 GIT 克隆

可访问GIT仓库直接克隆代码库:

git clone git@github.com:Hesong-OpenSource/sbusr.git
2.1.2 直接使用项目代码

访问 https://github.com/Hesong-OpenSource/sbusr ,从页面下载所需要的版本

也可联系作者索取项目代码

2.2 修改目录结构

下载之后,将源代码放在一个新建的目录,如 /your/dir/sbusr 该项目的目录结构是:

sbusr
  `-src
      `-methods
          |-xxx.py
          |-xxx.py
          |-xxx.py
          `-...py

src 目录中的所有文件移动到项目的根目录中,使得该项目的目录结构变为:

sbusr
  `-methods
    |-xxx.py
    |-xxx.py
    |-xxx.py
    `-...py
3 安装依赖包

我们建议在 Python 虚拟环境中安装依赖包。如果您准备将本项目的依赖包安装到系统全局的Python包集合,忽略本节中有关虚拟环境的步骤。

首先,在命令行中进入项目所在目录:

cd /your/dir/sbusr

如果准备将本项目的依赖包安装到 虚拟环境 中,请首先建立一个名为 _env 虚拟环境目录(该目录名称可任意指定):

Python3.4以及以上版本执行:

python -m venv _env

否则执行:

virtualenv _env

然后进入虚拟环境:

POSIX 下执行:

source _env/bin/activate

Windows 下执行:

_env/Scripts/activate

现在,可以使用 pip 安装所有的依赖包:

python -m pip install -r requirments.txt

提示

本程序除 Python stdlib 外的依赖包有:

注意

smartbus-client-python 在安装之后,还需要相应的C语言共享/动态文件,请仔细阅读 smartbus-client-python api doc

smartbus客户端的共享/动态文件可以在 https://github.com/Hesong-OpenSource/smartbus-client-sdk 下载。

注意

由第三方提供的各个 RPC 模块可能有各自不同的包依赖。 如:提供 HTTP Restful API 访问的 RPC 模块可能依赖于 requests ; 提供 MySQL 访问的 RPC 模块可能依赖于 mysql-connector-python 。 请酌情处理。

4 启动程序

执行:

python sbusr_run.py run

启动这个程序

执行:

python sbusr_run.py --help

查看其具体的命令行参数

命令行

sbusr_run

编写自定义 RPC

扩展 methods 包

sbusrmethods 包中的模块视作 RPC 模块,并根据 IPSC 发送的 RPC 请求,执行 methods 包中对应的可调用对象。

RPC 作者应将扩展模块放在 methods 包中。

名为 a.b 的 RPC 方法对应的 sbusr 函数将是 methods.a.b

自定义 RPC 例子

以下举例说明:

在包的“根”编写RPC函数

methods/__init__.py 文件中定义一个名为 add() 的函数:

def add(a, b):
    return a + b

该函数的完整路径名是 methods.add() ,当接收到 RPC 请求后,sbusr 会将 RPC 中的 method 名称加上 methods 作为要调用的函数。 本例中,IPSC如果要调用 add() ,其 RPC 的 method 属性就应该是 add 。这个过程是:

  1. IPSC发出RPC请求:

    {"method": "add", "params": [1, 2]}
    
  2. sbusr执行:

    methods.add(1, 2)
    
  3. sbusr返回RPC结果:

    {"result": 3}
    
在子模块编写RPC函数

新建模块文件 methods/weather.py 文件,在该文件中定义一个名为 sk() 的函数,用这个函数来获取某地的当前天气信息:

def sk(code):
    import requests
    return requests.get('http://www.weather.com.cn/data/sk/{0}.html'.format(code)).json()

其过程是:

  1. IPSC发出RPC请求:

    {"method": "weather.sk", "params": ["101010100"]}
    
  2. sbusr执行:

    methods.weather.sk("101010100")
    
  3. sbusr返回RPC结果:

    {"result": {"weatherinfo":{"city":"北京","cityid":"101010100","temp":"-1","WD":"北风","WS":"1级","SD":"56%","WSE":"1","time":"09:40","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暂无实况","qy":"1027"}}}
    
使用类方法作为RPC函数

类方法也可以作为RPC函数

新建一个模块文件 methods/mymodule.py

class MyClass:

    @classmethod
    def mymethod(cls):
        # codes here ....
        pass

那么, methods.mymodule.MyClass.mymethod() 所对应的 RPC 方法就是 mymodule.MyClass.mymethod()

其过程是:

  1. IPSC发出RPC请求:

    {"method": "mymodule.MyClass.mymethod", "params": []}
    
  2. sbusr执行:

    methods.mymodule.MyClass.mymethod()
    
  3. sbusr将方法的返回值作为RPC返回结果

注意

如果RPC方法定义在类中,该方法必须是类方法或静态方法

限制与注意事项

阻塞

RPC在进程池中执行。RPC作者应该在函数执行完毕后立即返回, 不要 阻塞子进程,以避免进程资源得不到释放。

全局变量

sbsur 在进程池中执行 methods 包中的RPC方法。 每个子进程的全局变量分属各个进程,不可互相访问。 一旦子进程重启,该进程中所有的全局变量都会丢失。

如果 settings.EXECUTOR_CONFIG 的参数 pool_maxtasksperchild 是一个正整数,子进程RPC执行次数到达该数值时,进程池将重启子进程,该进程的全局变量、函数都会重新加载,原有的数据将全部丢失。

重新加载 也会重启子进程,造成全局变量丢失。

所以,如果自定义RPC模块需要保留“会话”数据,那么这些数据只能保存在外部(如数据库、文件), 不能保存在内存变量中

资源释放

在进程池模式下,开发者不要在RPC模块中开启无法释放的资源(如HTTP服务),以便进程池释放资源。

所以,RPC模块只能扮演“客户端”的角色,而不能作为服务器。

IPSC 集成

sbusr 通过 smartbus 与 IPSC 流程进行通信。

sbusr 提供了两种通信方式:

  • 在流程中使用脚本远程调用 sbusr 中方法
  • 通过 HTTP Request 命令 sbusr 启动流程

RPC 调用

基本原理

如果要在流程中调用 sbusr 的方法,需要通过在“脚本节点”中运行脚本实现:

  • 在流程中,通过脚本函数 smartbusSendDatasbusr 异步发送RPC的请求数据。
  • sbusr 根据RPC请求执行其内部的某个函数或方法,并将结果通过smartbus返回给流程
  • 流程发送RPC请求后,通过脚本函数 SmartbusWaitNotify 异步等待等待并收取 sbusr 返回的执行结果
格式定义

RPC请求-回复的格式请参考 JSON-RPC 2.0 specification

请求格式

RPC请求一律由流程通过 smartbusSendDatasbusr 异步发送

调用者应使用该函数的 data 参数传入RPC请求的JSON字符串。

例如,要将 echo() RPC请求发送到 unitid=19, clientid=1sbusr 实例,应该这样在流程的脚本节点中执行:

smartbusSendData(19, 1, -1, 1, 211, json.dumps({
            "jsonrpc": "2.0",
            "id": "123456",
            "method": "echo",
            "params": ["Hello"]
        })
    )

注意

cmdtype 参数的值必须是 211

sbusr 收到该请求后,将执行函数:

methods.echo("Hello")
回复格式

流程在发送请求之后,使用异步等待函数 SmartbusWaitNotify 等待RPC返回。

sbusr 将 RPC的 id 作为 title 参数传入,返回结果以JSON格式通过该函数返回。

例如,我们需要接收上例中 id"123456" 的RPC执行结果,就在流程的脚本节点中执行:

res = AsynchInvoke(SmartbusWaitNotify("123456", 0, 1000))
resobj = json.loads(res)
if 'result' in resobj:
    Trace('返回值是:%s'%(res['result']))
elif 'error' in resobj:
    TraceErr('返回错误:%s : %s'%(res['error']['code'], res['error']['message']))

注意

由于IPSC脚本引擎的限制, AsynchInvoke 所在行不能换行书写!

sbusr 自定义脚本

为了简化调用步骤,我们提供了封装上述“请求-回复”过程的自定义脚本,请参见 http://github.com/Hesong-OpenSource/sbusr-flow-scripts

启动流程

sbusr 提供一个迷你型的 HTTP 服务器,并在 /api/flow 这个路径上接受 POST 请求。调用方可向该HTTP地址发送POST请求启动流程。

流程参数格式

流程启动参数一律使用编码为UTF-8的JSON对象在POST请求的BODY中定义。这个JSON对象的属性有:

server:

要启动流程的IPSC服务在Smartbus体系中的 unitid

如果不提供该参数,则 sbusr 会随机的从它所能连接到的IPSC中选择一个

数据类型:Number (非负整数)
process:

要启动流程的IPSC服务在Smartbus体系中的 clientid

如果不提供该参数,则 sbusr 会随机的从它所能连接到的IPSC中选择一个

数据类型:Number (非负整数)
project:

流程所项目的ID

数据类型:String
flow:

流程的ID

数据类型:String
params:

传入流程“子流程开始”节点的参数列表

数据类型:Array

举例:

POST /api/flow HTTP/1.1
Content-Type: application/json

{
    "project": "Project1",
    "flow": "Flow1",
    "params": ["Hello", "Flow"]
}

收到该请求后, sbusr 将从它连接到的IPSC实例中随机选择一个,并让该IPSC启动项目ID为“Project1”,流程ID为“Flow1”的流程,流程启动后,其“子项目开始节点”可以接收到两个参数,分别是“Hello” 与“Flow”。

如果流程启动成功, sbusr 返回 HTTP 200 OK,否则返回错误码。

重新加载

sbusrmethods 包可以重新加载。重加载特性使得动态修改自定义RPC成为可能。

以下几种方式可以实现 sbusrmethods 包重加载:

  • sbusr 发送重加载命令
  • sbusr 子进程执行任务数到达最大值后自动重加载
  • 杀死子进程后,父进程自动重启子进程达到重加载的目的

注意

无论哪种方式, sbusr 都是通过重启子进程来完成 methods 包的重加载的。

设置子进程最大任务数

如果设置了 settings.EXECUTOR_CONFIGpool_maxtasksperchild 属性为正整数,执行RPC的子进程会在该属性定义的最大执行次数后重启。此时, methods 模块上也会因重启而被重加载。

发送重加载命令

sbusr 通过其内置 Web 服务器接收重加载命令。

重启命令是发送到 http://host[:port]/sys/reset 的 HTTP GET 请求。可使用任何 HTTP 客户端来发送该命令,如:

curl http://localhost:8080/sys/reset

注解

Web 服务器的监听端口通过变量 settings.WEBSERVER_LISTEN 设置

杀死子进程

杀死子进程后,父进程自动重启子进程达到重加载的目的。

警告

这种方式有危险,不要使用!

配置

sbusr的配置记录在文件 settings.py 中,使用者应直接修改该模块(源文件)的代码改变配置。

大部分设置在sbusr重启后方生效。

详细信息请参见 settings

API 手册

API

executor module

该模块定义了 RPC 任务执行器

服务器模块 server 将来自 smartbus 的请求传递给执行器类 Executor 的实例, 执行器解析请求的 JSON RPC 格式,并分配执行体,在线程池中执行, 然后返回结果。

date:2013-12-14
author:刘雪彦 <lxy@hesong.net>
class executor.Executor(queue_maxsize=0, pool_processes=None, pool_maxtasksperchild=None)

基类:logging.handlers.QueueListener

smarbus JSON RPC 请求执行器

使用进程池执行 RPC 请求

参数:
  • queue_maxsize – 任务队列最大值 默认为0,表示无限制。
  • pool_processes – 执行器池的最大数量 默认为 none,表示使用 CPU 核心数量作为其最大值
  • pool_maxtasksperchild – 进程池最大执行数量 默认为 None,表示无限制。超过该值,则重启子进程。仅对进程池模型有效。

在接收到 smartbus 请求后,需要向这个队列放置数据,数据的格式是: client, pack_info, txt 分别是:收到数据的 smartbus 客户端的实例,数据包附加信息,数据文本。

收到数据后,本类型的实例将按照 JSON-RPC 格式解析数据,并执行 JSON RPC 请求,最后将执行结果通过 smartbus 客户端进行返回。 返回数据格式是符合 JSON RPC 标准的字符串。

handle(record)
put(client, pack_info, txt)
start()
stop()

globalvars module

记录一些全局变量,特别是需要跨进程访问的全局变量

date:2013-12-20
author:刘雪彦 <lxy@hesong.net>
globalvars.executor = None

全局 RPC 执行器

类型是 executor.Executor

注意

仅在主进程有效

globalvars.ipc_smartbusclient = None

IPC客户端

注意

仅在主进程有效

globalvars.ipsc_set = set()

IPSC节点集合

一个 set 类型全局变量 进程池模式中,它仅在主进程有效

将Smartbus上的IPSC客户端记录在这个集合中,其中每个元素表示一个IPSC客户端连接,其格式是:

(unitid, clientid)

注意

仅在主进程有效

globalvars.main_logging_listener = None

多进程的全局日志监听器

注意

仅在主进程有效

globalvars.main_logging_queue = None

多进程的全局日志队列

注意

仅在主进程有效

globalvars.net_smartbusclients = []

NET客户端列表

注意

仅在主进程有效

globalvars.prog_args = None

命令行参数

注解

在主进程初始化进程池的时候,该变量在子进程中被赋值

jsonrpc module

JSON-RPC 常用方法

date:2013-12-13
author:刘雪彦 <lxy@hesong.net>
exception jsonrpc.Error(id_=None, code=None, message=None, data=None)

基类:builtins.Exception

json rpc 的 Error Response 对象

to_dict()

转为 dict

to_json()

转为 JSON 字符串

exception jsonrpc.FormatError(id_=None, code=-32700, message='Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.', data=None)

基类:jsonrpc.Error

JSON-RPC格式错误

exception jsonrpc.InvalidErrorError(id_=None, code=-32600, message='The JSON sent is not a valid Error object.', data=None)

基类:jsonrpc.Error

无效的JSON-RPC错误回复

exception jsonrpc.InvalidParamsError(id_=None, code=-32602, message='Invalid method parameter(s).', data=None)

基类:jsonrpc.Error

无效的JSON-RPC请求参数

exception jsonrpc.InvalidRequestError(id_=None, code=-32600, message='The JSON sent is not a valid Request object.', data=None)

基类:jsonrpc.Error

无效的JSON-RPC请求

exception jsonrpc.InvalidResponseError(id_=None, code=-32600, message='The JSON sent is not a valid Response object.', data=None)

基类:jsonrpc.Error

无效的JSON-RPC回复

exception jsonrpc.MethodNotFoundError(id_=None, code=-32601, message='The method does not exist / is not available.', data=None)

基类:jsonrpc.Error

JSON-RPC请求方法未找到

exception jsonrpc.RpcTimeoutError

基类:builtins.Exception

jsonrpc.parse(txt)

解析 JSON RPC

参数:txt – 带解析的 JSON 字符串
返回:request, result, error 如果是request,第一个参数返回该请求的dict,格式是:
{'id': 'id-of-the-request', 'method': 'your_method', params['what', 'ever', 'params']}

其它两个参数是 None

如果是返回结果,第二个参数返回结果 dict,格式是:

{'id': 'id-of-the-request', 'result': 'your_result'}

其它两个参数是 None

jsonrpc.recursive_jsonable(obj, encoding='utf-8')

递归转为可JSON序列化数据类型

参数:
  • obj – 要转化的对象,可以是基本数据类型,或者 dict, list, tuple, date, datetime
  • encoding – 编码,默认是utf8
返回:

转换后对象

jsonrpc.to_bytes(s, encoding='utf-8')
jsonrpc.to_str(s, encoding='utf-8')
jsonrpc.to_unicode(s, encoding='utf-8')

loggingqueue module

class loggingqueue.QueueHandler(queue)

基类:logging.Handler

This handler sends events to a queue. Typically, it would be used together with a multiprocessing Queue to centralise logging to file in one process (in a multi-process application), so as to avoid file write contention between processes.

This code is new in Python 3.2, but this class can be copy pasted into user code for use with earlier Python versions.

emit(record)

Emit a record.

Writes the LogRecord to the queue, preparing it for pickling first.

enqueue(record)

Enqueue a record.

The base implementation uses put_nowait. You may want to override this method if you want to use blocking, timeouts or custom queue implementations.

prepare(record)

Prepares a record for queuing. The object returned by this method is enqueued.

The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place.

You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact.

class loggingqueue.QueueListener(queue, *handlers)

基类:builtins.object

This class implements an internal threaded listener which watches for LogRecords being added to a queue, removes them and passes them to a list of handlers for processing.

dequeue(block)

Dequeue a record and return it, optionally blocking.

The base implementation uses get. You may want to override this method if you want to use timeouts or work with custom queue implementations.

enqueue_sentinel()

This is used to enqueue the sentinel record.

The base implementation uses put_nowait. You may want to override this method if you want to use timeouts or work with custom queue implementations.

handle(record)

Handle a record.

This just loops through the handlers offering them the record to handle.

prepare(record)

Prepare a record for handling.

This method just returns the passed-in record. You may want to override this method if you need to do any custom marshalling or manipulation of the record before passing it to the handlers.

start()

Start the listener.

This starts up a background thread to monitor the queue for LogRecords to process.

stop()

Stop the listener.

This asks the thread to terminate, and then waits for it to do so. Note that if you don’t call this before your application exits, there may be some records still left on the queue, which won’t be processed.

methods package

Subpackages
methods.bar package
Subpackages
methods.bar.boo package
Submodules
methods.bar.boo.loo module
class methods.bar.boo.loo.Loo

基类:builtins.object

classmethod dec(a, b)
Module contents
methods.bar.boo.boo_echo(txt)
Module contents
Submodules
methods.foo module
class methods.foo.Foo

基类:builtins.object

classmethod echo(txt)
Module contents

自定义RPC模块

开发者可在该名称空间下放置所需的远程方法

本模块下的几个函数是简单的远程方法示例

class methods.BuildIn

基类:builtins.object

classmethod sum(*args)
methods.add(a, b)

加法

methods.echo(txt)

原样返回收到的内容

参数:txt (str) – 字符串
返回:原样返回 txt 字符串
返回类型:str
methods.exception(*args)

抛出异常

methods.plus(*args)

求和

methods.sleep(seconds)

睡眠

参数:seconds (float) – 睡眠时间,时间为秒
methods.warnlog(msg)

在 Logging 中输出警告信息

参数:msg (str) – 警告信息

sbusr_run module

sbsur_run 命令行

运行 sbusr 服务程序

author:刘雪彦 <lxy@hesong.net>
copyright:2013 Hesong Info-Tech. All rights reserved.
contact:lxy@hesong.net

在当前终端/命令行窗口中运行该程序

直接运行:

POSIX(需要权限):

./sbusr_run.py <option>

Windows(需要权限与文件关联):

sbusr_run.py <option>        

使用 Python 运行:

python sbusr_run.py <option>
-V, --version

显示版本信息。

-v, --verbose

输出更详细的日志。默认为 False

-h, --help

输出帮助信息

-W, --no-web-server

不启动该程序的内嵌web服务器模块

警告

如果不启动Web服务器模块,则无法调用流程,也无法通过命令重启子进程。

server module

服务

date:2013-12-13
author:刘雪彦 <lxy@hesong.net>

该模块负责:

  • 维持smartbus客户端的连接
  • 分配及执行来自smartbus的任务,并返回结果。
  • 启动Web程序
server.run(args)

运行服务

参数:args – 命令行参数

注意

该函数将“阻塞”,直到服务结束才会返回

server.stop()

停止服务

注意

该函数是异步的,在它执行后, server.run() 将会退出 IOLoop ,但是 stop 的返回与之无关。

settings module

配置

date:2014-12-26
author:刘雪彦 <lxy@hesong.net>
settings.EXECUTOR_CONFIG = {'pool_processes': 1, 'pool_maxtasksperchild': 1000, 'queue_maxsize': 1000}

执行器设置

这个设置被用于 executor.Executor 构造函数的传入参数。

参数:
  • queue_maxsize – 任务队列最大值。0,表示无限制。
  • pool_processes – 执行器池的最大数量。 None 表示使用 CPU 核心数量作为其最大值。
  • pool_maxtasksperchild – 进程池最大执行数量。 None 表示无限制。超过该值,则重启子进程。

警告

不得删除该变量,不得修改该变量的结构。

settings.FLOW_ACK_TIMEOUT = 15

流程调用时等待调用结果的最大时间,单位是秒

settings.LOGGING_CONFIG = {'loggers': {'smartbus.ipcclient.client.Client': {'level': 'INFO', 'handlers': ['smartbusFile']}, 'smartbus.netclient.client.Client': {'level': 'INFO', 'handlers': ['smartbusFile']}}, 'version': 1, 'root': {'level': 'INFO', 'handlers': ['console', 'file', 'fileErr']}, 'handlers': {'file': {'formatter': 'normal', 'backupCount': 1000, 'level': 'DEBUG', 'maxBytes': 10485760, 'filename': '../logs/log', 'class': 'logging.handlers.RotatingFileHandler'}, 'consoleErr': {'formatter': 'normal', 'stream': 'ext://sys.stderr', 'level': 'ERROR', 'class': 'logging.StreamHandler'}, 'smartbusFile': {'formatter': 'normal', 'filename': '../logs/smartbus', 'backupCount': 1000, 'maxBytes': 10485760, 'class': 'logging.handlers.RotatingFileHandler'}, 'fileErr': {'formatter': 'normal', 'backupCount': 1000, 'level': 'ERROR', 'maxBytes': 10485760, 'filename': '../logs/err', 'class': 'logging.handlers.RotatingFileHandler'}, 'console': {'formatter': 'normal', 'stream': 'ext://sys.stdout', 'class': 'logging.StreamHandler'}}, 'formatters': {'normal': {'format': '%(asctime)s <%(processName)-10s,%(threadName)-10s> %(levelname)-8s %(name)s - %(message)s'}}}

日志设置

其格式请参考: https://docs.python.org/2/library/logging.config.html#configuration-dictionary-schemahttps://docs.python.org/3/library/logging.config.html#configuration-dictionary-schema

settings.SMARTBUS_CONFIG = {'type': 'net', 'initialize': {'unitid': 19}, 'clients': [{'masterPort': 8089, 'encoding': 'utf-8', 'localClientId': 0, 'authorPwd': None, 'authorUsr': None, 'slaverHost': None, 'extInfo': None, 'localClientType': 19, 'slaverPort': 0, 'masterHost': '10.4.62.45'}]}

SmartBus客户端配置

参数:
  • type

    smartbus客户端类型,有效值:"net""ipc"

    • "net" : 使用smartbus网络通信客户端
    • "ipc" : 使用smartbus进程通信客户端
  • initialize

    smartbus客户端模块初始化参数属性字段

    • type 属性为 "net" 时,该属性必须设置一个属性 unitid
    • type 属性为 "ipc" 时,该属性必须设置两个属性 clientidclienttype

    具体含义请参考 smartbus 文档

  • instance

    smartbus进程通信客户端地址参数属性字段

    该 dict 属性需要设置3个属性:

    • username
    • password
    • extInfo

    具体含义请参考 smartbus 文档

    注意

    仅当 type 属性为 "ipc" 时有效

  • clients

    smartbus网络通信客户端地址参数属性字段

    该 list 属性的每个成员表示一个smartbus网络通信客户端,每个客户端的参数都是:

    • localClientId
    • localClientType
    • masterHost
    • masterPort
    • slaverHost
    • slaverPort
    • authorUsr
    • authorPwd
    • extInfo

    具体含义请参考 smartbus 文档

    注意

    仅当 type 属性为 "net" 时有效

settings.SMARTBUS_NOTIFY_TTL = 10000

通过smartbus发送给IPSC流程的notify消息的生存期(ms)

settings.WEBSERVER_LISTEN = (8080, '')

WEB 服务器监听端口与地址.

格式是:

(port, address)

警告

不得删除该变量,不得修改该变量的结构。

webhandlers module

Web Request Handlers

date:2014-12-29
author:刘雪彦 <lxy@hesong.net>
class webhandlers.FlowHandler(application, request, **kwargs)

基类:tornado.web.RequestHandler

POST启动流程

on_connection_close()
post(*args, **kwargs)
classmethod set_flow_ack(ack)

设置流程启动执行回执

参数:ack (webhandlers.FlowInvokeAck) – 回执信息
class webhandlers.FlowInvokeAck(packinfo, project, invokeid, ack, msg)

基类:builtins.object

class webhandlers.ResetHandler(application, request, **kwargs)

基类:tornado.web.RequestHandler

get()
reset_executor()