factor 0.6.5 → 0.6.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de59489e42da320e68f586ec424afe9ca68ca25a
4
- data.tar.gz: 314cc835b4304aa42a40d3827e4abe24f648a50d
3
+ metadata.gz: af39fc9efe3999659f027cfc4cdf50a2c40c4533
4
+ data.tar.gz: deebd96954ace642c46f23f9fdb6b038c6ad4d99
5
5
  SHA512:
6
- metadata.gz: 9e240a8437547554f5aeb5036315057e23a5dffb2477c0ad6bd12a3dfd4511f961763d14daaa2cdcf0c98b29b9015868b3b3e594d1264fc322587ec55cbb5f5d
7
- data.tar.gz: 9c56560e8cf41062d0629042d01e4bbcbea5102dd452cca4df67a3fb4883ccddbab2170ec98f122224465b1b05130f3e476756f1b13249a6b5c359e49a2f03b3
6
+ metadata.gz: f85d0d40425675967ca5b8b01709a36ae06803560be6fe10e633a26e6bdb897a7ffebbb0c905062332dcb642e3dc0e0d8075949fc2e1c77bd8286ccd40192899
7
+ data.tar.gz: a7dcd984dba299c0812f69e0b7da04aebf5d9bfa1cf16039384e6f5bd2ba35be0bc339837589f4b3569114204122a9db1875ee667504e84fa9980af89c8fdcbf
data/lib/commands.rb CHANGED
@@ -5,6 +5,7 @@ require 'commander/import'
5
5
  require 'factor/version'
6
6
  require 'commands/workflow_command'
7
7
  require 'commands/registry_command'
8
+ require 'commands/run_command'
8
9
 
9
10
  program :name, 'Factor.io Server'
10
11
  program :version, Factor::VERSION
@@ -20,6 +21,14 @@ command 'server' do |c|
20
21
  c.when_called Factor::Commands::WorkflowCommand, :server
21
22
  end
22
23
 
24
+ command 'run' do |c|
25
+ c.syntax = 'factor run service_address params'
26
+ c.description = 'Run a specific command.'
27
+ c.option '--credentials FILE', String, 'credentials.yml file path.'
28
+ c.option '--connectors FILE', String, 'connectors.yml file path'
29
+ c.when_called Factor::Commands::RunCommand, :run
30
+ end
31
+
23
32
  command 'cloud' do |c|
24
33
  c.syntax = 'factor host <account id> <workflow id> <api key>'
25
34
  c.description = 'Start the Factor.io Server using your workflows and credentials from Factor.io Cloud'
@@ -35,9 +44,10 @@ end
35
44
 
36
45
  command 'registry workflows add' do |c|
37
46
  c.syntax = 'factor registry workflow add <id>'
38
- c.description = 'Get list of available workflows'
47
+ c.description = 'Add a workflow to your working directory'
39
48
  c.option '--credentials FILE', String, 'credentials.yml file path.'
40
49
  c.option '--connectors FILE', String, 'connectors.yml file path'
50
+ c.option '--path FILE', String, 'Path to workflows'
41
51
  c.option '--values \'{"api_key":"foo"}\'', String, "{}"
42
52
  c.when_called Factor::Commands::RegistryCommand, :add_workflow
43
53
  end
@@ -48,7 +58,7 @@ command 'registry connectors' do |c|
48
58
  c.when_called Factor::Commands::RegistryCommand, :connectors
49
59
  end
50
60
 
51
- command 'registry connector add' do |c|
61
+ command 'registry connectors add' do |c|
52
62
  c.syntax = 'factor registry connector add <id>'
53
63
  c.description = 'Get list of available connectors'
54
64
  c.option '--credentials FILE', String, 'credentials.yml file path.'
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'configatron'
4
+
5
+ require 'commands/base'
6
+ require 'runtime/workflow'
7
+
8
+ require 'pp'
9
+
10
+ module Factor
11
+ module Commands
12
+ class RunCommand < Factor::Commands::Command
13
+ def initialize
14
+ @workflows = {}
15
+ super
16
+ end
17
+
18
+ def run(args, options)
19
+ config_settings = {}
20
+ config_settings[:credentials] = options.credentials
21
+ config_settings[:connectors] = options.connectors
22
+ load_config(config_settings)
23
+
24
+ connector_settings = configatron.connectors.to_hash
25
+ credential_settings = configatron.credentials.to_hash
26
+ runtime = Factor::Runtime::Workflow.new(connector_settings, credential_settings, logger: logger)
27
+
28
+ begin
29
+ params = JSON.parse(args[1] || '{}')
30
+ rescue => ex
31
+ logger.error "'#{args[1]}' can't be parsed as JSON"
32
+ end
33
+
34
+ if params
35
+ EM.run do
36
+ runtime.run(args[0],params) do |response_info|
37
+ data = response_info.is_a?(Array) ? response_info.map {|i| i.marshal_dump} : response_info.marshal_dump
38
+ JSON.pretty_generate(data).split("\n").each do |line|
39
+ logger.info line
40
+ end
41
+ EM.stop
42
+ end.on_fail do
43
+ EM.stop
44
+ end
45
+ end
46
+
47
+ logger.info 'Good bye!'
48
+ end
49
+ end
50
+
51
+
52
+
53
+ private
54
+
55
+ def block_until_interupt
56
+ logger.info 'Ctrl-c to exit'
57
+ begin
58
+ loop do
59
+ sleep 1
60
+ end
61
+ rescue Interrupt
62
+ logger.info 'Exiting app...'
63
+ end
64
+ end
65
+
66
+
67
+ end
68
+ end
69
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Primary Factor.io module
4
4
  module Factor
5
- VERSION = '0.6.5'
5
+ VERSION = '0.6.6'
6
6
  end
@@ -84,7 +84,7 @@ module Factor
84
84
  message = " #{action_response['message']}"
85
85
  notify :log, status: action_response['status'], message: message
86
86
  when 'start_workflow'
87
- notify :start_workflow, action_response
87
+ notify :start_workflow, action_response['payload']
88
88
  else
89
89
  notify :log, status:'error', message: "Unknown action response: #{action_response}"
90
90
  end
@@ -73,7 +73,7 @@ module Factor
73
73
 
74
74
  caller.on :start_workflow do |data|
75
75
  success "Listener '#{address}' triggered"
76
- block.call(Factor::Common.simple_object_convert(data['payload']))
76
+ block.call(Factor::Common.simple_object_convert(data)) if block
77
77
  end
78
78
 
79
79
  caller.on :fail do |info|
@@ -85,7 +85,8 @@ module Factor
85
85
  @logger.log log_info[:status], log_info
86
86
  end
87
87
 
88
- caller.listen(address.id,params)
88
+ service_credentials = @credentials[address.service.to_sym] || {}
89
+ caller.listen(address.id,params.merge(service_credentials))
89
90
  end
90
91
  e
91
92
  end
@@ -128,24 +129,24 @@ module Factor
128
129
  caller.on :return do |data|
129
130
  success "Action '#{address}' responded"
130
131
  caller.close
131
- block.call(Factor::Common.simple_object_convert(data['payload']))
132
+ block.call(Factor::Common.simple_object_convert(data)) if block
132
133
  end
133
134
 
134
135
  caller.on :close do
135
136
  error "Action '#{address}' disconnected"
136
- e.fail_block.call(action_response) if e.fail_block
137
137
  end
138
138
 
139
139
  caller.on :fail do |info|
140
140
  error "Action '#{address}' failed"
141
- e.fail_block.call(action_response) if e.fail_block
141
+ e.fail_block.call(info) if e.fail_block
142
142
  end
143
143
 
144
144
  caller.on :log do |log_info|
145
145
  @logger.log log_info[:status], log_info
146
146
  end
147
147
 
148
- caller.action(address.id,params)
148
+ service_credentials = @credentials[address.service.to_sym] || {}
149
+ caller.action(address.id,params.merge(service_credentials))
149
150
  end
150
151
  e
151
152
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -149,6 +149,7 @@ files:
149
149
  - lib/commands.rb
150
150
  - lib/commands/base.rb
151
151
  - lib/commands/registry_command.rb
152
+ - lib/commands/run_command.rb
152
153
  - lib/commands/workflow_command.rb
153
154
  - lib/common/deep_struct.rb
154
155
  - lib/factor/version.rb