由於最近自己寫點小東西,需要有工作流程管理方面的應用,所有的環境為Ruby on rails,所有在選擇流程引擎的時候選擇了ruote,但是對於ruote是完全陌生的,所以在這里記下點滴,如果理解的不正確,還請大家批評指正。
Ruote:用Ruby寫的一個工作流引擎。
開始了解Ruote先要了解幾個很重要的概念:
- storage 是ruote的核心,保存這所有的持續流程。Storage實現線程安全,多個工作可以同時使用。
- worker 圍繞在Storage周圍的流程本省。
- engine(dashboard) 包含一些圖標和按鈕,是所有進程實例的控制面板,能夠對進程實例就行運行,暫停,取消操作。
下面是一個Ruote的配置:
1 require 'ruote' 2 require 'ruote/storage/fs_storage' 3 4 engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::FsStorage.new('work')))
這是一個最簡單的配置,將engin,worker和storate包裝在一起。
Engine的配置選項實際上是在初始化的時候傳遞給存儲的,比如:
1 require 'ruote' 2 require 'ruote/storage/fs_storage' 3 4 engine = Ruote::Engine.new( 5 Ruote::Worker.new( 6 Ruote::FsStorage.new( 7 'work', 8 'remote_definition_allowed' => true, 'ruby_eval_allowed' => true)))
也可以向下面這樣定義:
1 engine = Ruote::Engine.new( 2 Ruote::Worker.new( 3 Ruote::FsStorage.new('work'))) 4 5 engine.configure('remote_definition_allowed', true) 6 engine.configure('ruby_eval_allowed', true)
Engin的配置項:
participant_threads_enabled(自從ruote2.3.0版本開始,默認情況是true)
默認情況下, 從work中調度一個流程給參與者的時候都用一個新的Ruby線程。這樣在默認情況下不會阻塞worker。
remote_definition_allowed(默認情況下是false)
Remote definitions 是通過Http協議過程定義。因為過程定義是代碼,默認情況下用如下方法是不允許的:
1 Ruote.process_definition :name => 'main process' do 2 sequence do 3 subprocess 'http://example.com/definitions/head_process.rb' 4 subprocess 'http://example.com/definitions/tail_process.rb' 5 end 6 end 7 8 # or 9 10 engine.variables['head'] = 'http://example.com/definitions/head_process.rb' 11 engine.variables['tail'] = 'http://example.com/definitions/tail_process.rb' 12 13 Ruote.process_definition :name => 'main process' do 14 sequence do 15 head 16 tail 17 end 18 end 19 20 # or simply 21 22 engine.launch('http://example.com/definitions/main.xml')
如果要使用如上的定義,那么應該將‘remote_definition_allowed的選項設置為"true"。
ruby_eval_allowed:(默認是false)
wait_logger_max:(默認是147)
這個設置只是在開發測試環境中一個worker的情況,在其他環境下不用管這個配置。WaitLogger是ruote的一個組件,追蹤147個最近的本地工作流程的處理信息。 preserve_configuration:(默認是false)
當這個配置設置為true的時候,engine,worker,storage將不向存儲后面持續工作流程寫配置。適用於多個工作流程一起運行的情境下。
restless_worker:(默認是false)
更像是一個工作流程的配置,當設置為true的時候,工作流程在提取信息和定時調度執行期間就不會sleep。
worker_state_enabled:(默認是false)
當設置為true的時候,將Ruote::Dashboard中的worker_state解鎖,可能的狀態包括running,paused,stopped.工作流讀取狀態執行相應的running,paused,stop操作。
engine on_error / on_terminate:
engine在發生錯誤和終止的時候觸發的事件或者參與者,如下定義:
1 # you can pass a participant name 2 engine.on_error = 'administrator' 3 4 # or a subprocess name 5 engine.on_error = 'error_procedure' 6 7 # or directly a subprocess definition 8 engine.on_error = Ruote.define do 9 concurrence do 10 administrator :msg => 'something went wrong' 11 supervisor :msg => 'something went wrong' 12 end 13 end
worker:
目前為止,沒有為worker的配置。
storage:
工作流、業務處理被人調用,持續好長時間,數據的持久性是必須的,storage用來保存數據。因為所有的工作流程共享storage,所以不僅要提供可靠的持久數據,而且可以避免工作流之間的沖突。
下面這個表中是實現的storage類型:
multiple workers:storage是否支持多個工作流程。
remote worker:現實工作流程是不是和storage在一個主機上
speed :顯示storage的速度排行。
Ruote::HashStorage:
一個字內存中臨時的storage,不能夠在多個工作流程中共享,大多數用於測試或者臨時的工作流程。
Ruote::FsStorage:
以json的格式將ruote的信息保存成文件,可以在多個工作流程中共享數據。
Ruote::Redis::Storage:
基於redis的storage,很快,在多個工作流程的情況下使用。
Ruote::Sequel::Storage:
通用的持久storage,使用Mysql或者PostgreSQL,在多個工作流程的情況下使用。
Ruote::Dm::Storage:
一個 DataMapper storage 實現。
Ruote::Couch::Storage:
一個基於 CouchDB 的Storage實現。
Ruote::Mon::Storage:
MongoDB storage 實現。
Ruote::Beanstalk::BsStorage:
提供一種技術,使FsStorage可以被遠程的工作流程可以使用。
十分想找對ruote熟悉的朋友共同學習。