论坛首页 编程语言技术论坛

写了一个简单的工作流引擎

浏览 23553 次
该帖已经被评为良好帖
作者 正文
   发表时间:2008-06-19  

仿照OSWORKFLOW写了一个简单的工作流引擎,支持简单流程,分支,合并等操作。

工作流所采用的数据库如下:

create table wf_instances(
	id integer primary key,
	name,
	filename,
	status	--CREATED, ACTIVATED, SUSPENDED, KILLED 和 COMPLETED
)
create table wf_curr_steps(
	id integer primary key,
	wf_instance_id integer,
	step integer,
	action integer,
	status,
	owner,
	started_at datetime,
	finished_at datetime,
	caller
)
create table wf_properties(
	id integer primary key,
	wf_instance_id integer,
	item_key,
	item_value
)
 

采用YAML来描述流程定义,比如一个请假流程的定义如下:

workflow:
  init-actions:
    1:
      name: 开始
      results:
        -
          step: 1
          status: 在填写
          owner: @wf_params['caller']
  steps:
    1:
      name: 填写请假单
      actions:
        1:
          name: 修改
          params:
            page-name: edit_leave
          results:
            -
              step: 1
              status: 在填写
              owner: @wf_params['caller']
        2:
          name: 提交申请
          params:
            page-name: apply_leave
          results:
            -
              condition: @wf_params['days'].to_i <= 3
              step: 2
              status: 待审核
              owner: 部门经理
            -
              step: 3
              status: 待审核
              owner: 公司领导
    2:
      name: 部门经理审核
      actions:
        1:
          name: 同意
          params:
            page-name: verify_leave
          results:
            -
              step: 4
              status: 待归档
              owner: 资料员
        2:
          name: 不同意
          params:
            page-name: verify_leave
          results:
            -
              step: 1
              status: 不同意
              owner: @wf_params['applier']
    3:
      name: 公司领导审核
      actions:
        1:
          name: 同意
          params:
            page-name: verify_leave
          results:
            -
              step: 4
              status: 待归档
              owner: 资料员
        2:
          name: 不同意
          params:
            page-name: verify_leave
          results:
            -
              step: 1
              status: 不同意
              owner: @wf_params['applier']
    4:
      name: 归档
      actions:
        1:
          name: 归档处理
          condition: curr_instance_step(4).status=='待归档'
          params:
            page-name: verify_leave
          results:
            -
              step: 4
              status: 已归档
              owner: 资料员

 

使用的基本方法介绍如下:

1、建立工作流实例:

@wf = Workflow.new(caller)
@wf_id = @wf.create('请假流程.yml', 2, nil)

2、执行一个ACTION:

@wf.do_action(@wf_id,step_id,action_id,wf_params)

3、获取当前可执行的动作:

@wf.available_actions(@wf_id,wf_params)

4、获取当前实例的全部全部STEP全部:

@wf.curr_steps(@wf_id)

5、删除工作流实例:

@wf.destroy(@wf_id)
 

 

   发表时间:2008-06-19  
很好,继续努力,成为ruby的第一个开源工作流
0 请登录后投票
   发表时间:2008-06-19  
redmine算不算是个开源的工作流呢?
0 请登录后投票
   发表时间:2008-06-19  
太粗糙了吧, 可以参考oswf等其他,结合中国国情的wf。
写出想法, 大家共同参与。 我想应该是很有前途的。
0 请登录后投票
   发表时间:2008-06-20  
呵呵,楼主精神可嘉!

虽然workflow原理不是很复杂,可感觉做一个成熟的workflow真的很难,需要投入巨大的研发力量。一个成熟的workflow产品至少要包含流程设计(一般都是支持傻瓜式的图形操作),Role管理,Form设计,业务逻辑控制模块等,用户管理模块。

我现在的工作就是做基于工作流进行二次开发。有成熟的workflow平台支持,感觉开发e-workflow类的电子流程系统效率还是挺高的。

目前我使用的是adobe workflow.公司花了不少钱买的。功能很强,就是开发工具傻了点,不过也没办法,产品好像都是这样。

0 请登录后投票
   发表时间:2008-06-21  

写的太粗糙,?Action定义怎么配置的?
0 请登录后投票
   发表时间:2008-06-21  
ltian 写道
Rocwo 写道
呵呵,楼主精神可嘉!

虽然workflow原理不是很复杂,可感觉做一个成熟的workflow真的很难,需要投入巨大的研发力量。一个成熟的workflow产品至少要包含流程设计(一般都是支持傻瓜式的图形操作),Role管理,Form设计,业务逻辑控制模块等,用户管理模块。

我现在的工作就是做基于工作流进行二次开发。有成熟的workflow平台支持,感觉开发e-workflow类的电子流程系统效率还是挺高的。

目前我使用的是adobe workflow.公司花了不少钱买的。功能很强,就是开发工具傻了点,不过也没办法,产品好像都是这样。


Role管理,业务逻辑控制模块等,用户管理模块。这些东西根本不属于工作流系统本身应该有的,因为不用工作流也会需要这些东西,工作流只是和这些东西有接口。

Form设计,也就是说工作单的开发吧,谁会用一个专用Form设计工具去开发工作单呢?更多的程序员还是用eclipse,vs等通用的开发工具开工作单。

楼上很正确, 工作流最重要的是引擎部分, 其他的给个接口就行了。
还有, 没必要用jaml吧?   用ruby   做dsl不是很好么?
0 请登录后投票
   发表时间:2008-06-21  
ltian 写道

Form设计,也就是说工作单的开发吧,谁会用一个专用Form设计工具去开发工作单呢?更多的程序员还是用eclipse,vs等通用的开发工具开工作单。

现在有些工作流产品带表单设计的,自定义表单+自定义流程,这是一大卖点。
0 请登录后投票
   发表时间:2008-06-23  
以前用过actionflow,rails的一个插件
0 请登录后投票
   发表时间:2008-06-23  
Godlikeme 写道

写的太粗糙,?Action定义怎么配置的?

 

一开始粗糙是难免的,Action定义在workflow——>steps——>actions中。在这里是用YAML描述的。

Action前后可以接受一段RUBY脚本,在before-action和after-action中定义。

 

下面再给出一个国土的案件查处流程:

 

workflow:
  init-actions:
    1:
      name: 开始
      results:
        -
          step: 1
          status: 受理
          owner: @wf_params['caller']+':案件受理人'
  steps:
    1:
      name: 受理
      actions:
        1:
          name: 修改
          condition: curr_instance_step(1).status=='受理'
          params:
            action-name: edit
          results:
            -
              step: 1
              status: 受理
              owner: @wf_params['caller']+':案件受理人'
        2:
          name: 删除
          condition: curr_instance_step(1).status=='受理'
          params:
            action-name: destroy
          results:
            -
              step: 1
              status: 受理
              owner: @wf_params['caller']+':案件受理人'
        3:
          name: 移交立案
          condition: curr_instance_step(1).status=='受理'
          params:
            action-name: comm_work
            doc-template: doc06
          results:
            -
              step: 2
              status: 立案
              owner: @wf_params['caller']+':案件立案人'
        4:
          name: 当场处罚
          condition: curr_instance_step(1).status=='受理'
          params:
            action-name: comm_work
            doc-template: doc05
          results:
            -
              step: 60
              status: 当场
              owner: @wf_params['caller']+':案件办理人'
    2:
      name: 立案
      actions:
        1:
          name: 立案窗口
          condition: curr_instance_step(2).status=='立案'
          params:
            action-name: edit_document
          results:
            -
              step: 2
              status: 立案
              owner: @wf_params['caller']+':案件立案人'
        2:
          name: 移交调查
          condition: curr_instance_step(2).status=='立案'
          params:
            action-name: comm_work
            doc-template: doc07 doc08 doc10 doc11 doc09 doc12
          results:
            -
              step: 3
              status: 调查
              owner: @wf_params['caller']+':案件调查人'
    3:
      name: 调查
      actions:
        1:
          name: 调查窗口
          condition: curr_instance_step(3).status=='调查'
          params:
            action-name: edit_document
          results:
            -
              step: 3
              status: 调查
              owner: @wf_params['caller']+':案件调查人'
        2:
          name: 移交审理
          condition: curr_instance_step(3).status=='调查'
          params:
            action-name: comm_work
            doc-template: doc13 doc14 doc15
          results:
            -
              step: 4
              status: 审理
              owner: @wf_params['caller']+':案件办理人'
    4:
      name: 审理
      actions:
        1:
          name: 审理窗口
          condition: curr_instance_step(4).status=='审理'
          params:
            action-name: edit_document
          results:
            -
              step: 4
              status: 审理
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 不予行政处罚
          condition: curr_instance_step(4).status=='审理'
          params:
            action-name: comm_work
            doc-template: doc16 doc27
          results:
            -
              step: 33
              status: 结案
              owner: @wf_params['caller']+':案件办理人'
        3:
          name: 处罚告知
          condition: curr_instance_step(4).status=='审理'
          params:
            action-name: comm_work
            doc-template: doc19
          results:
            -
              step: 30
              status: 告知
              owner: @wf_params['caller']+':案件办理人'
        4:
          name: 撤案
          condition: curr_instance_step(4).status=='审理'
          params:
            action-name: comm_work
            doc-template: doc17
          results:
            -
              step: 40
              status: 撤案
              owner: @wf_params['caller']+':案件办理人'
    30:
      name: 告知
      actions:
        1:
          name: 告知窗口
          condition: curr_instance_step(30).status=='告知'
          params:
            action-name: edit_document
          results:
            -
              step: 30
              status: 告知
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 移交处罚决定
          condition: curr_instance_step(30).status=='告知'
          params:
            action-name: comm_work
            doc-template: doc23 doc24
          results:
            -
              step: 31
              status: 处罚
              owner: @wf_params['caller']+':案件办理人'
    31:
      name: 处罚
      actions:
        1:
          name: 处罚决定窗口
          condition: curr_instance_step(31).status=='处罚'
          params:
            action-name: edit_document
          results:
            -
              step: 31
              status: 处罚
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 移交执行
          condition: curr_instance_step(31).status=='处罚'
          params:
            action-name: comm_work
            doc-template: doc25 doc26
          results:
            -
              step: 32
              status: 执行
              owner: @wf_params['caller']+':案件办理人'
    32:
      name: 执行
      actions:
        1:
          name: 执行窗口
          condition: curr_instance_step(32).status=='执行'
          params:
            action-name: edit_document
          results:
            -
              step: 32
              status: 执行
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 移交结案
          condition: curr_instance_step(32).status=='执行'
          params:
            action-name: comm_work
            doc-template: doc27
          results:
            -
              step: 33
              status: 结案
              owner: @wf_params['caller']+':案件办理人'
    33:
      name: 结案
      actions:
        1:
          name: 结案窗口
          condition: curr_instance_step(33).status=='结案'
          params:
            action-name: edit_document
          results:
            -
              step: 33
              status: 结案
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 完成
          condition: curr_instance_step(33).status=='结案'
          params:
            action-name: comm_work
            doc-template: 
          results:
            -
              step: 90
              status: 结案
              owner: @wf_params['caller']+':案件办理人'
    40:
      name: 撤案
      actions:
        1:
          name: 撤案窗口
          condition: curr_instance_step(40).status=='撤案'
          params:
            action-name: edit_document
          results:
            -
              step: 40
              status: 撤案
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 完成
          condition: curr_instance_step(40).status=='撤案'
          params:
            action-name: comm_work
            doc-template: 
          results:
            -
              step: 90
              status: 撤案
              owner: @wf_params['caller']+':案件办理人'
    60:
      name: 当场
      actions:
        1:
          name: 当场处罚窗口
          condition: curr_instance_step(60).status=='当场'
          params:
            action-name: edit_document
          results:
            -
              step: 60
              status: 当场
              owner: @wf_params['caller']+':案件办理人'
        2:
          name: 移交执行
          condition: curr_instance_step(60).status=='当场'
          params:
            action-name: comm_work
            doc-template: doc25 doc26
          results:
            -
              step: 32
              status: 执行
              owner: @wf_params['caller']+':案件办理人'
    90:
      name: 完成
      actions:
        1:
          name: 完成处理
          auto: true
          after-action: |
            law_case = LawCase.find_by_wf_instance_id @wf_instance.id
            if law_case
              law_case.wf_instance_id = nil
              law_case.status = '完成'
              law_case.save!
            end
            @wf_instance.destroy
          results:
            -
              step: 90
              status: 完成
 
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics