marty 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86520af8c5b4d0f802cee4528502584f94d81eac
4
- data.tar.gz: 1f6d2122fe80662c839ae2abd7fab0bc4512a1f4
3
+ metadata.gz: 74092a6c860ba6143a686a653e304abd173f7b1e
4
+ data.tar.gz: 7e18178b04dacec033571c2566c653043d27116a
5
5
  SHA512:
6
- metadata.gz: 88edfb46b139d22027b17a43573beb85d252415cfee6f0eea1028d166a38792bf964cab12c74a5adac38b1eee836097d85ad27ff69cf54ab8211ca3aac4e6a7c
7
- data.tar.gz: 587c829255481f5c00b490ba7ff57c041289b928135951b1c7b2033a73d3c3e523a41c5d147f22a5bfefeef568dc4c9a9cc8290c46600acddc854620a50d035a
6
+ metadata.gz: c9666aa7555d70c078cb27745206af4ae51dfa6728d21f0cb637d1736cb106b19228c6056c51d16a3a923f1630ee732a93768ca252d7fde6ecc7229a1f091586
7
+ data.tar.gz: 675388c07330499a07f89705c7887eadaf0da17cef12c65c0ae914ca55d3c59062e08676c6af36aff1b6891827b94348849ccb3770fe6cbc66577b70c5775bc9
@@ -6,6 +6,7 @@ class Marty::RpcController < ActionController::Base
6
6
  params["attrs"] || "[]",
7
7
  params["params"] || "{}",
8
8
  params["api_key"] || nil,
9
+ params["background"],
9
10
  )
10
11
 
11
12
  respond_to do |format|
@@ -16,48 +17,49 @@ class Marty::RpcController < ActionController::Base
16
17
  send_data Marty::DataExporter.to_csv(res)
17
18
  }
18
19
  end
19
-
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def do_eval(sname, tag, node, attrs, params, api_key)
24
+ def do_eval(sname, tag, node, attrs, params, api_key, background)
25
+ err = "Marty::RpcController#do_eval,"
26
+
25
27
  unless attrs.is_a?(String)
26
- logger.info "Marty::RpcController#do_eval, Bad attrs (must be a string): <#{attrs.inspect}>"
28
+ logger.info "#{err} Bad attrs (must be a string): <#{attrs.inspect}>"
27
29
  return {error: "Bad attrs"}
28
30
  end
29
31
 
30
32
  begin
31
33
  attrs = ActiveSupport::JSON.decode(attrs)
32
34
  rescue JSON::ParserError => e
33
- logger.info "Marty::RpcController#do_eval, Malformed attrs (json parse error): #{attrs.inspect}, #{e.message}"
35
+ logger.info "#{err} Malformed attrs (json): #{attrs.inspect}, #{e.message}"
34
36
  return {error: "Malformed attrs"}
35
37
  end
36
38
 
37
39
  unless attrs.is_a?(Array) && attrs.all? {|x| x.is_a? String}
38
- logger.info "Marty::RpcController#do_eval, Malformed attrs (must be array of strings): <#{attrs.inspect}>"
40
+ logger.info "#{err} Malformed attrs (not string array): <#{attrs.inspect}>"
39
41
  return {error: "Malformed attrs"}
40
42
  end
41
43
 
42
44
  unless params.is_a?(String)
43
- logger.info "Marty::RpcController#do_eval, Bad params (must be a string): <#{params.inspect}>"
45
+ logger.info "#{err} Bad params (must be a string): <#{params.inspect}>"
44
46
  return {error: "Bad params"}
45
47
  end
46
48
 
47
49
  begin
48
50
  params = ActiveSupport::JSON.decode(params)
49
51
  rescue JSON::ParserError => e
50
- logger.info "Marty::RpcController#do_eval, Malformed params (json parse error): <#{params.inspect}>, #{e.message}"
52
+ logger.info "#{err} Malformed params (json): <#{params.inspect}>, #{e.message}"
51
53
  return {error: "Malformed params"}
52
54
  end
53
55
 
54
56
  unless params.is_a?(Hash)
55
- logger.info "Marty::RpcController#do_eval, Malformed params (must be a hash): <#{params.inspect}>"
57
+ logger.info "#{err} Malformed params (not hash): <#{params.inspect}>"
56
58
  return {error: "Malformed params"}
57
59
  end
58
60
 
59
61
  unless Marty::ApiAuth.authorized?(sname, api_key)
60
- logger.info "Marty::RpcController#do_eval, permission denied"
62
+ logger.info "#{err} permission denied"
61
63
  return {error: "Permission denied" }
62
64
  end
63
65
 
@@ -66,15 +68,20 @@ class Marty::RpcController < ActionController::Base
66
68
  rescue => e
67
69
  err_msg = "Can't get engine: #{sname || 'nil'} with tag: " +
68
70
  "#{tag || 'nil'}; message: #{e.message}"
69
- logger.info "Marty::RpcController#do_eval, #{err_msg}"
71
+ logger.info "#{err} #{err_msg}"
70
72
  return {error: err_msg}
71
73
  end
72
74
 
73
75
  begin
74
- engine.evaluate_attrs(node, attrs, params)
76
+ if background
77
+ result = engine.background_eval(node, params, attrs)
78
+ {"job_id" => result.__promise__.id}
79
+ else
80
+ engine.evaluate_attrs(node, attrs, params)
81
+ end
75
82
  rescue => exc
76
83
  err_msg = Delorean::Engine.grok_runtime_exception(exc)
77
- logger.info "Marty::RpcController#do_eval, Evaluation error: #{err_msg}"
84
+ logger.info "#{err} Evaluation error: #{err_msg}"
78
85
  err_msg
79
86
  end
80
87
  end
data/lib/marty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "1.0.10"
2
+ VERSION = "1.0.11"
3
3
  end
@@ -91,10 +91,33 @@ describe Marty::RpcController do
91
91
  node: "B",
92
92
  attrs: ["e","f"].to_json,
93
93
  tag: t1.name,
94
- params: { a: 333, d: 5}.to_json
94
+ params: { a: 333, d: 5}.to_json,
95
95
  }
96
96
  expect(response.body).to eq([4,20].to_json)
97
97
  end
98
+
99
+ it "should be able to post background job" do
100
+ Delayed::Worker.delay_jobs = false
101
+ post 'evaluate', {
102
+ format: :json,
103
+ script: "M1",
104
+ node: "B",
105
+ attrs: ["e","f"].to_json,
106
+ tag: t1.name,
107
+ params: { a: 333, d: 5}.to_json,
108
+ background: true,
109
+ }
110
+ res = ActiveSupport::JSON.decode response.body
111
+ expect(res).to include('job_id')
112
+ job_id = res['job_id']
113
+
114
+ promise = Marty::Promise.find_by_id(job_id)
115
+
116
+ expect(promise.result).to eq({"e"=>4, "f"=>20})
117
+
118
+ Delayed::Worker.delay_jobs = true
119
+ end
120
+
98
121
  it "should be able to post with complex data" do
99
122
  post 'evaluate', {
100
123
  format: :json,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani