waylon-core 0.1.8 → 0.2.1

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
  SHA256:
3
- metadata.gz: 4d396f88fe34083537cabbe245d1063ecd1b8c0d15e5391c80eb0a9f4902aa39
4
- data.tar.gz: bc7d2a6b5da80e36508032d3bcfaa59f91395d016e0fb69e65a24c56366f26e3
3
+ metadata.gz: 4b2b3afe461da0b2a61930ff43324ffc820bb596e88de8f36daed751a8ec68fa
4
+ data.tar.gz: 2901833fc47c1ab6f8778137de3b3c917cdaf464d09138caac82ec74e45edbe6
5
5
  SHA512:
6
- metadata.gz: 229980e2a8c719c57baa00a26d137a10c6677fe1081adfc3aa73f4bfd13c83ee74c1f8b10933ba43688a9d40fa8e0c71c264cbbe7dec40ec202192ade05e4b1c
7
- data.tar.gz: 82814e648a191b886619f8e15bf6b934b8c1cbc6112d77f39a1bbcf96f0b5def15267260609a45b46c3c8252a98d569e454c07f754c4baa39b1ee0aba8923c92
6
+ metadata.gz: 61e60d22426e107eba2b3b07ff3481c6be533cb658d6b8cff402af18c947b9d9e8cd933b1bb137922410741445f83331418552ce3d3e79e290b1f75588bb41d8
7
+ data.tar.gz: b98cc02351ac0092fbc138c139c8ef1a3c87a5067b4f4890a0937d6c24af60088c4db4b570158a0cd0f79089493443f29aea8fa37c1d3a5d0e64100702e43706
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waylon-core (0.1.8)
4
+ waylon-core (0.2.1)
5
5
  addressable (~> 2.8)
6
6
  faraday (~> 1.8)
7
7
  i18n (~> 1.8)
@@ -14,13 +14,14 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- addressable (2.8.0)
18
- public_suffix (>= 2.0.2, < 5.0)
17
+ addressable (2.8.1)
18
+ public_suffix (>= 2.0.2, < 6.0)
19
19
  ast (2.4.2)
20
20
  concurrent-ruby (1.1.10)
21
+ connection_pool (2.2.5)
21
22
  diff-lcs (1.5.0)
22
23
  docile (1.4.0)
23
- faraday (1.10.0)
24
+ faraday (1.10.2)
24
25
  faraday-em_http (~> 1.0)
25
26
  faraday-em_synchrony (~> 1.0)
26
27
  faraday-excon (~> 1.1)
@@ -44,34 +45,37 @@ GEM
44
45
  faraday-rack (1.0.0)
45
46
  faraday-retry (1.0.3)
46
47
  ffi (1.15.5)
47
- i18n (1.10.0)
48
+ i18n (1.12.0)
48
49
  concurrent-ruby (~> 1.0)
49
50
  json (2.6.2)
50
51
  moneta (1.5.1)
51
52
  mono_logger (1.1.1)
52
53
  multi_json (1.15.0)
53
- multipart-post (2.2.0)
54
- mustermann (1.1.1)
54
+ multipart-post (2.2.3)
55
+ mustermann (2.0.2)
55
56
  ruby2_keywords (~> 0.0.1)
56
57
  nio4r (2.5.8)
57
58
  parallel (1.22.1)
58
- parser (3.1.2.0)
59
+ parser (3.1.2.1)
59
60
  ast (~> 2.4.1)
60
- public_suffix (4.0.7)
61
- puma (5.6.4)
61
+ public_suffix (5.0.0)
62
+ puma (5.6.5)
62
63
  nio4r (~> 2.0)
63
- rack (2.2.3.1)
64
- rack-protection (2.2.0)
64
+ rack (2.2.4)
65
+ rack-protection (2.2.2)
65
66
  rack
66
67
  rainbow (3.1.1)
67
68
  rake (13.0.6)
68
69
  rbnacl (7.1.1)
69
70
  ffi
70
- redis (4.6.0)
71
- redis-namespace (1.8.2)
72
- redis (>= 3.0.4)
71
+ redis (5.0.1)
72
+ redis-client (~> 0.7)
73
+ redis-client (0.7.1)
74
+ connection_pool
75
+ redis-namespace (1.9.0)
76
+ redis (>= 4)
73
77
  regexp_parser (2.5.0)
74
- resque (2.2.1)
78
+ resque (2.3.0)
75
79
  mono_logger (~> 1.0)
76
80
  multi_json (~> 1.0)
77
81
  redis-namespace (~> 1.6)
@@ -90,21 +94,22 @@ GEM
90
94
  diff-lcs (>= 1.2.0, < 2.0)
91
95
  rspec-support (~> 3.11.0)
92
96
  rspec-support (3.11.0)
93
- rubocop (1.30.1)
97
+ rubocop (1.35.1)
98
+ json (~> 2.3)
94
99
  parallel (~> 1.10)
95
- parser (>= 3.1.0.0)
100
+ parser (>= 3.1.2.1)
96
101
  rainbow (>= 2.2.2, < 4.0)
97
102
  regexp_parser (>= 1.8, < 3.0)
98
103
  rexml (>= 3.2.5, < 4.0)
99
- rubocop-ast (>= 1.18.0, < 2.0)
104
+ rubocop-ast (>= 1.20.1, < 2.0)
100
105
  ruby-progressbar (~> 1.7)
101
106
  unicode-display_width (>= 1.4.0, < 3.0)
102
- rubocop-ast (1.18.0)
107
+ rubocop-ast (1.21.0)
103
108
  parser (>= 3.1.1.0)
104
109
  rubocop-rake (0.6.0)
105
110
  rubocop (~> 1.0)
106
- rubocop-rspec (2.11.1)
107
- rubocop (~> 1.19)
111
+ rubocop-rspec (2.12.1)
112
+ rubocop (~> 1.31)
108
113
  ruby-progressbar (1.11.0)
109
114
  ruby2_keywords (0.0.5)
110
115
  simplecov (0.21.2)
@@ -113,13 +118,13 @@ GEM
113
118
  simplecov_json_formatter (~> 0.1)
114
119
  simplecov-html (0.12.3)
115
120
  simplecov_json_formatter (0.1.4)
116
- sinatra (2.2.0)
117
- mustermann (~> 1.0)
121
+ sinatra (2.2.2)
122
+ mustermann (~> 2.0)
118
123
  rack (~> 2.2)
119
- rack-protection (= 2.2.0)
124
+ rack-protection (= 2.2.2)
120
125
  tilt (~> 2.0)
121
- tilt (2.0.10)
122
- unicode-display_width (2.1.0)
126
+ tilt (2.0.11)
127
+ unicode-display_width (2.2.0)
123
128
  webrick (1.7.0)
124
129
  yard (0.9.28)
125
130
  webrick (~> 1.7.0)
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waylon
4
+ # Used for working with the Moneta store for caching
5
+ module Cache
6
+ DefaultStorage = Moneta.new(
7
+ :Redis,
8
+ url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1"
9
+ )
10
+
11
+ def self.clear
12
+ storage.clear
13
+ end
14
+
15
+ def self.delete(key)
16
+ storage.delete(key)
17
+ end
18
+
19
+ def self.key?(name)
20
+ storage.key?(name)
21
+ end
22
+
23
+ def self.load(key, expires: nil)
24
+ expires ? storage.load(key, expires: expires) : storage.load(key)
25
+ end
26
+
27
+ def self.store(key, value, expires: nil)
28
+ if expires
29
+ storage.store(key, value, expires: expires)
30
+ else
31
+ storage.store(key, value)
32
+ end
33
+ end
34
+
35
+ def self.storage
36
+ @storage ||= DefaultStorage
37
+ end
38
+
39
+ def self.storage=(storage)
40
+ @storage = storage
41
+ end
42
+ end
43
+ end
data/lib/waylon/config.rb CHANGED
@@ -32,11 +32,10 @@ module Waylon
32
32
 
33
33
  # Load in the config from env variables
34
34
  # @return [Boolean] Was the configuration loaded?
35
- def load_env # rubocop:disable Metrics/AbcSize
35
+ def load_env
36
36
  @schema ||= {}
37
37
  self["global.log.level"] = ENV.fetch("LOG_LEVEL", "info")
38
- self["global.redis.host"] = ENV.fetch("REDIS_HOST", "redis")
39
- self["global.redis.port"] = ENV.fetch("REDIS_PORT", "6379")
38
+ self["global.redis"] = ENV.fetch("REDIS", "localhost:6379")
40
39
  self["global.admins"] = ENV.fetch("GLOBAL_ADMINS", "")
41
40
  ENV.keys.grep(/CONF_/).each do |env_key|
42
41
  conf_key = env_key.downcase.split("_")[1..].join(".")
@@ -49,13 +48,13 @@ module Waylon
49
48
  # Provides the redis host used for most of Waylon's brain
50
49
  # @return [String] The redis host
51
50
  def redis_host
52
- self["global.redis.host"]
51
+ self["global.redis"].split(":").first
53
52
  end
54
53
 
55
54
  # Provides the redis port used for most of Waylon's brain
56
55
  # @return [String] The redis host
57
56
  def redis_port
58
- self["global.redis.port"]
57
+ self["global.redis"].split(":").last
59
58
  end
60
59
 
61
60
  # Clear the configuration
data/lib/waylon/core.rb CHANGED
@@ -27,6 +27,7 @@ require "sinatra"
27
27
 
28
28
  # Internal requirements
29
29
  require "waylon/version"
30
+ require "waylon/cache"
30
31
  require "waylon/config"
31
32
  require "waylon/generic_exception"
32
33
  require "waylon/exceptions/not_implemented_error"
@@ -19,8 +19,7 @@ require "waylon/rspec/test_worker"
19
19
  config = Waylon::Config.instance
20
20
  config.load_env
21
21
 
22
- Waylon::Cache = Moneta.new(:Cookie)
23
- p Waylon::Storage
22
+ Waylon::Cache.store = Moneta.new(:Cookie)
24
23
  Waylon::Logger.log("Found Global Admins: #{config.admins}")
25
24
 
26
25
  Waylon::RSpec::TestUser.find_or_create(
data/lib/waylon/rspec.rb CHANGED
@@ -46,5 +46,5 @@ module Waylon
46
46
  end
47
47
  end
48
48
 
49
- Waylon::Cache = Moneta.new(:Cookie)
50
- Waylon::Storage::Store = Moneta.new(:Cookie)
49
+ Waylon::Cache.storage = Moneta.new(:Cookie)
50
+ Waylon::Storage.storage = Moneta.new(:Cookie)
@@ -23,10 +23,10 @@ module Waylon
23
23
  response << "*Skill plugins:*"
24
24
  loaded_routes.each { |d| response << " - #{d}" }
25
25
  response << "*Redis:*"
26
- state, read_time, write_time = test_redis
26
+ state, raw_read_time, raw_write_time, read_time, write_time = test_redis
27
27
  response << " - *Test Result:* #{state ? "Success" : "Error"}"
28
- response << " - *Read time:* #{read_time}s"
29
- response << " - *Write time:* #{write_time}s"
28
+ response << " - *Read time:* #{read_time}s (raw: #{raw_read_time}s)"
29
+ response << " - *Write time:* #{write_time}s (raw: #{raw_write_time}s)"
30
30
  if Resque.redis.connected?
31
31
  response << "*Queue Monitoring:*"
32
32
  response << " - Failed jobs: #{Resque::Failure.count}"
@@ -43,17 +43,27 @@ module Waylon
43
43
  SenseRegistry.instance.senses.map { |_s, c| c.name }.sort.uniq
44
44
  end
45
45
 
46
- def test_redis
47
- test_key = ("a".."z").to_a.sample(10).join
46
+ def test_redis # rubocop:disable Metrics/AbcSize
47
+ test_key1 = ("a".."z").to_a.sample(10).join
48
+ test_key2 = ("a".."z").to_a.sample(10).join
48
49
  test_value = (0..1000).to_a.sample(20).map(&:to_s).join
49
50
  test_result = nil
50
51
 
51
- write_time = Benchmark.realtime { db.store(test_key, test_value) }
52
- read_time = Benchmark.realtime { test_result = db.load(test_key) }
52
+ raw_write_time = Benchmark.realtime { cache(test_key1) { test_value } }
53
+ raw_read_time = Benchmark.realtime { cache(test_key1) { test_value } }
54
+ enc_write_time = Benchmark.realtime { db.store(test_key2, test_value) }
55
+ enc_read_time = Benchmark.realtime { test_result = db.load(test_key2) }
53
56
 
54
- db.delete(test_key)
57
+ db.delete(test_key1)
58
+ db.delete(test_key2)
55
59
 
56
- [(test_value == test_result), read_time.round(6), write_time.round(6)]
60
+ [
61
+ (test_value == test_result),
62
+ raw_read_time.round(6),
63
+ raw_write_time.round(6),
64
+ enc_read_time.round(6),
65
+ enc_write_time.round(6)
66
+ ]
57
67
  end
58
68
  end
59
69
  end
@@ -3,9 +3,9 @@
3
3
  module Waylon
4
4
  # Used for working with the Moneta store
5
5
  module Storage
6
- Store = Moneta.new(
6
+ DefaultStorage = Moneta.new(
7
7
  :Redis,
8
- url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1"
8
+ url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/2"
9
9
  )
10
10
 
11
11
  def self.cipher
@@ -14,16 +14,20 @@ module Waylon
14
14
  end
15
15
 
16
16
  def self.clear
17
- Store.clear
17
+ storage.clear
18
+ end
19
+
20
+ def self.delete(key)
21
+ storage.delete(key)
18
22
  end
19
23
 
20
24
  def self.key?(name)
21
- Store.key?(name)
25
+ storage.key?(name)
22
26
  end
23
27
 
24
28
  def self.load(key)
25
29
  this_cipher = cipher
26
- raw = Store.load(key)
30
+ raw = storage.load(key)
27
31
  return nil unless raw
28
32
 
29
33
  decoded = Base64.decode64(raw)
@@ -31,11 +35,19 @@ module Waylon
31
35
  JSON.parse(plain)
32
36
  end
33
37
 
38
+ def self.storage
39
+ @storage ||= DefaultStorage
40
+ end
41
+
42
+ def self.storage=(storage)
43
+ @storage = storage
44
+ end
45
+
34
46
  def self.store(key, value)
35
47
  this_cipher = cipher
36
48
  encrypted = this_cipher.encrypt(value.to_json)
37
49
  encoded = Base64.encode64(encrypted)
38
- Store.store(key, encoded)
50
+ storage.store(key, encoded)
39
51
  end
40
52
  end
41
53
  end
@@ -5,8 +5,8 @@ module Waylon
5
5
  # The Waylon::Core version
6
6
  VERSION = [
7
7
  0, # Major
8
- 1, # Minor
9
- 8 # Patch
8
+ 2, # Minor
9
+ 1 # Patch
10
10
  ].join(".")
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waylon-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-17 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -261,6 +261,7 @@ files:
261
261
  - bin/console
262
262
  - bin/setup
263
263
  - lib/waylon/base_component.rb
264
+ - lib/waylon/cache.rb
264
265
  - lib/waylon/condition.rb
265
266
  - lib/waylon/conditions/black_hole.rb
266
267
  - lib/waylon/conditions/default.rb