rule_engine_client 0.1.7 → 0.1.8

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rule_engine_client.rb +25 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88f3786ff4362f1ceeb46506da3baab444fba7b0eac521f9cee43f5fd8315f07
4
- data.tar.gz: a90cbd08601515f6daba925cbc536ad721531ae56b5d830440e0b023089b24ad
3
+ metadata.gz: c4b11c9fc54e518590ffa6936dab7cc05bf8e11ab318b42f385958975f103cc2
4
+ data.tar.gz: 6a774411a6c983e01d1310f575970aad67a71bc6dc141d2c569d4233c709cf71
5
5
  SHA512:
6
- metadata.gz: 2b10f616cccb602c031eb549feaf6821c9782dc4c9bc2f74e74acf130f0f716c1d66f2d2d583f4e0044e54d5ce1e7a14e519b5df470d41181350832cb57e830c
7
- data.tar.gz: 10abf6b421f4572f41e63817fe2ee02af50b86ce084504d3769e5425da24d0119031260626bcc3907d2103bdbd8c41f4d3a082a55dd31c914cf230f7b0046e5c
6
+ metadata.gz: d9c406296710023ea0cc9916d9a4139d06a2b7f0d182098f7f41bf159810a8cd3e861cb555dbe11ebb5959d038f4697fc25b6ad56e9508261bd231f11eeb7b1a
7
+ data.tar.gz: 50c045fed276f553f67c66e13943e61aaf3e451665488d569f41374f95c7d781123162651b4b695d39a2a22c8cf1bd4d237c11e23ffcff2f8a0597f14b95f485
@@ -5,16 +5,16 @@ require 'timeout'
5
5
 
6
6
  # rule engine client class
7
7
  class RuleEngineClient
8
- def initialize(server = 'http://localhost:8088', time_out_duration = 5, verbose = false)
8
+ def initialize(server = 'http://localhost:8088', request_timeout_in_s = 5, verbose = false)
9
9
  @server = server
10
10
  @verbose = verbose
11
11
  @logger = Logger.new($stdout)
12
- @time_out_duration = time_out_duration
12
+ @request_timeout_in_s = request_timeout_in_s
13
13
  log("rule engine '#{server}' client is initialized")
14
14
  end
15
15
 
16
16
  def log(message)
17
- @logger.debug("debug: #{message}") if @verbose
17
+ @logger.debug("rule engine: #{message}") if @verbose
18
18
  end
19
19
 
20
20
  def valid_json?(obj)
@@ -53,11 +53,11 @@ class RuleEngineClient
53
53
  response_hash(code, body, errors)
54
54
  end
55
55
 
56
- def evaluate(work_space, params, mode = 'production')
57
- url = URI.parse("#{@server}/run?e=#{work_space}&m=#{mode}")
56
+ def evaluate(engine, params, mode = 'production')
57
+ url = URI.parse("#{@server}/run?e=#{engine}&m=#{mode}")
58
58
  log("Will send post request: #{url}")
59
59
  begin
60
- Timeout.timeout(@time_out_duration) do
60
+ Timeout.timeout(@request_timeout_in_s) do
61
61
  http = Net::HTTP.new(url.host, url.port)
62
62
  http.use_ssl = true if url.instance_of? URI::HTTPS
63
63
  request = Net::HTTP::Post.new(url.request_uri)
@@ -76,15 +76,24 @@ class RuleEngineClient
76
76
  end
77
77
  end
78
78
 
79
- def work_space_exists?(work_space)
80
- log("checking if work space (#{work_space}) exists")
81
- url = URI.parse("http://#{@server}/engine/export?e=#{work_space}")
82
- req = Net::HTTP::Get.new(url.to_s)
83
- response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
84
- work_space_exists = response.code == 200
85
-
86
- log_message = work_space_exists ? "work space #{work_space} exists" : "work space #{work_space} not found"
87
- log(log_message)
88
- work_space_exists
79
+ def engine_exists?(engine)
80
+ log("checking if engine (#{engine}) exists")
81
+ url = URI.parse("#{@server}/engine/export?e=#{engine}")
82
+ begin
83
+ Timeout.timeout(@request_timeout_in_s) do
84
+ http = Net::HTTP.new(url.host, url.port)
85
+ http.use_ssl = true if url.instance_of? URI::HTTPS
86
+ request = Net::HTTP::Get.new(url.request_uri)
87
+ request['Content-Type'] = 'application/json'
88
+ response = http.request(request)
89
+ engine_exists = response.code == '200'
90
+ log_message = engine_exists ? "engine #{engine} exists" : "engine #{engine} not found"
91
+ log(log_message)
92
+ engine_exists
93
+ end
94
+ rescue Timeout::Error
95
+ log('HTTP Gatway timeout!')
96
+ false
97
+ end
89
98
  end
90
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rule_engine_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Areej Nour
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: integration with rule server
14
14
  email: