lib/runtime/engine.rb in factor-0.0.92 vs lib/runtime/engine.rb in factor-0.0.93
- old
+ new
@@ -25,11 +25,11 @@
# load the channel by referencing the .rb file
# the filename is lowercase with "_" for spaces
# and the module inside must be camal cased to match
# once loaded it is in the channel_modules Hash
def load_channel filename
- file=File.new filename
+ file= filename.is_a?(String) ? File.new filename : filename
require file
channel_module_name = File.basename(file).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
channel_module= self.class.const_get(channel_module_name)
@channel_modules[channel_module.definition["module"]]=channel_module
end
@@ -65,42 +65,48 @@
instance_id
end
# start your engines. vroom vrooooom!
def start
- @message_bus.start do
- @message_bus.listen do |message|
- if @workflows.include? message.workflow
- workflow = @workflows[message.workflow]
- activity = workflow.get_activity(message.position)
- if !activity.nil?
- action = activity["action"]
- channel = activity["channel"]
- method = activity["method"]
- target = activity["target"]
+ begin
+ @message_bus.start do
+ @message_bus.listen do |message|
+ if @workflows.include? message.workflow
+ workflow = @workflows[message.workflow]
+ activity = workflow.get_activity(message.position)
+ if !activity.nil?
+ action = activity["action"]
+ channel = activity["channel"]
+ method = activity["method"]
+ target = activity["target"]
- if match(target)
+ if match(target)
- values = message.body.merge(@credentials)
- # this maps the input values passed in with the templated defined in the workflow
- params = Hash.new
- activity["params"].each do |key,template|
- params[key]=Mustache.render(template,values)
- end
- event = call_channel_method(channel,method,params)
+ values = message.body.merge(@credentials)
+ # this maps the input values passed in with the templated defined in the workflow
+ params = Hash.new
+ activity["params"].each do |key,template|
+ params[key]=Mustache.render(template,values)
+ end
+ event = call_channel_method(channel,method,params)
- response_message = message.respond(event.params,event.class.name.split("::").last)
+ response_message = message.respond(event.params,event.class.name.split("::").last)
- @message_bus.send response_message
- end
+ @message_bus.send response_message
+ end
+ end
+ else
+ # workflow doesn't exist
end
- else
- # workflow doesn't exist
end
end
+ rescue SystemExit, Interrupt
+ "done"
+ rescue Exception => ex
+ ex
end
end
def call_channel_method(channel_name,class_name,params)
channel_module = @channel_modules[channel_name]
\ No newline at end of file