factor 0.0.92 → 0.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cli/server_task.rb +22 -17
- data/lib/client/client.rb +4 -3
- data/lib/runtime/engine.rb +30 -24
- metadata +1 -1
data/lib/cli/server_task.rb
CHANGED
@@ -13,53 +13,58 @@ module Factor
|
|
13
13
|
options.tags.each {|tag,value| engine.tag(tag,value)} if options.tags?
|
14
14
|
|
15
15
|
# load channels from server
|
16
|
-
|
16
|
+
say "loading channels from server"
|
17
17
|
engine = @client.load_channels(engine) do |message|
|
18
|
-
|
18
|
+
say " #{message}"
|
19
19
|
end
|
20
20
|
|
21
21
|
# load channels from files
|
22
22
|
if options.channels?
|
23
23
|
options.channels.each do |file|
|
24
24
|
full_file=File.expand_path(file)
|
25
|
-
|
25
|
+
say " loading '#{full_file}'"
|
26
26
|
engine.load_channel(full_file)
|
27
|
-
|
27
|
+
say " loaded '#{full_file}'"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
say "loading channels complete"
|
32
32
|
|
33
33
|
|
34
34
|
# load workflows from server
|
35
|
-
|
35
|
+
say "loading workflows from server"
|
36
36
|
engine = @client.load_workflows(engine) do |message|
|
37
|
-
|
37
|
+
say " #{message}"
|
38
38
|
end
|
39
|
-
|
39
|
+
say "loading workflows complete"
|
40
40
|
|
41
|
-
|
41
|
+
say "loading credentials from server"
|
42
42
|
engine = @client.load_credentials(engine) do |message|
|
43
|
-
|
43
|
+
say " #{message}"
|
44
44
|
end
|
45
|
-
|
46
|
-
|
47
|
-
puts "starting the server..."
|
48
|
-
engine.start
|
45
|
+
say "loading credentials complete"
|
49
46
|
|
47
|
+
say "starting the server...", :green
|
48
|
+
message = engine.start
|
49
|
+
if message.is_a?(Exception)
|
50
|
+
say "An unknown exception occured '#{message}'", :red
|
51
|
+
else
|
52
|
+
say "disconnecting...", :green
|
53
|
+
end
|
54
|
+
|
50
55
|
end
|
51
56
|
|
52
57
|
desc "list", "list all the running servers"
|
53
58
|
def list
|
54
|
-
|
59
|
+
say "listing all servers"
|
55
60
|
end
|
56
61
|
|
57
62
|
desc "logs", "listen to incoming logs"
|
58
63
|
def logs
|
59
64
|
engine = Factor::Runtime::Engine.new(get_config[:email],get_config[:token])
|
60
|
-
|
65
|
+
say "Listening...", :green
|
61
66
|
engine.logs do |message|
|
62
|
-
|
67
|
+
say "[#{message.route}] #{message.body}"
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
data/lib/client/client.rb
CHANGED
@@ -61,7 +61,8 @@ module Factor
|
|
61
61
|
uri = URI.parse(channel['zip_url'])
|
62
62
|
|
63
63
|
# temp file to store the zip for download
|
64
|
-
temp_file = Tempfile.new([uri.path.gsub(/\W+/,'-'), '.zip'], :encoding => 'ascii-8bit')
|
64
|
+
#temp_file = Tempfile.new([uri.path.gsub(/\W+/,'-'), '.zip'], :encoding => 'ascii-8bit')
|
65
|
+
temp_file = Tempfile.new([uri.to_s.gsub(/\W+/,'-'), '.zip'])
|
65
66
|
|
66
67
|
# temp directory where zip will be decompressed
|
67
68
|
unzip_dir=temp_file.path[0..-5]
|
@@ -77,8 +78,8 @@ module Factor
|
|
77
78
|
unzip(temp_file.path,unzip_dir)
|
78
79
|
|
79
80
|
code.call("loading '#{channel['zip_url']}' into engine")
|
80
|
-
Dir.glob("#{unzip_dir}/**/*.rb").each do |
|
81
|
-
engine.load_channel(
|
81
|
+
Dir.glob("#{unzip_dir}/**/*.rb").each do |ruby_file_name|
|
82
|
+
engine.load_channel(ruby_file_name)
|
82
83
|
end
|
83
84
|
|
84
85
|
end
|
data/lib/runtime/engine.rb
CHANGED
@@ -27,7 +27,7 @@ module Factor
|
|
27
27
|
# and the module inside must be camal cased to match
|
28
28
|
# once loaded it is in the channel_modules Hash
|
29
29
|
def load_channel filename
|
30
|
-
file=File.new filename
|
30
|
+
file= filename.is_a?(String) ? File.new filename : filename
|
31
31
|
require file
|
32
32
|
channel_module_name = File.basename(file).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
|
33
33
|
channel_module= self.class.const_get(channel_module_name)
|
@@ -67,39 +67,45 @@ module Factor
|
|
67
67
|
|
68
68
|
# start your engines. vroom vrooooom!
|
69
69
|
def start
|
70
|
-
|
71
|
-
@message_bus.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
begin
|
71
|
+
@message_bus.start do
|
72
|
+
@message_bus.listen do |message|
|
73
|
+
if @workflows.include? message.workflow
|
74
|
+
workflow = @workflows[message.workflow]
|
75
|
+
activity = workflow.get_activity(message.position)
|
76
|
+
if !activity.nil?
|
77
|
+
action = activity["action"]
|
78
|
+
channel = activity["channel"]
|
79
|
+
method = activity["method"]
|
80
|
+
target = activity["target"]
|
80
81
|
|
81
82
|
|
82
|
-
|
83
|
+
if match(target)
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
values = message.body.merge(@credentials)
|
86
|
+
# this maps the input values passed in with the templated defined in the workflow
|
87
|
+
params = Hash.new
|
88
|
+
activity["params"].each do |key,template|
|
89
|
+
params[key]=Mustache.render(template,values)
|
90
|
+
end
|
91
|
+
event = call_channel_method(channel,method,params)
|
91
92
|
|
92
|
-
|
93
|
+
response_message = message.respond(event.params,event.class.name.split("::").last)
|
93
94
|
|
94
95
|
|
95
|
-
|
96
|
-
|
96
|
+
@message_bus.send response_message
|
97
|
+
end
|
97
98
|
|
99
|
+
end
|
100
|
+
else
|
101
|
+
# workflow doesn't exist
|
98
102
|
end
|
99
|
-
else
|
100
|
-
# workflow doesn't exist
|
101
103
|
end
|
102
104
|
end
|
105
|
+
rescue SystemExit, Interrupt
|
106
|
+
"done"
|
107
|
+
rescue Exception => ex
|
108
|
+
ex
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|