waylon-core 0.1.9 → 0.2.2

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: 628f00817729895a327ec3adff832ba15fdb071da3762a061eb637b0492b2953
4
- data.tar.gz: 17276d8b5acbdaf2b5c90766329d53ec8fe42d0afae64f7aa062ad0a4cb1a381
3
+ metadata.gz: 1aebd152f6a966ba3af1d42c2538ee64aa63f23b369defa8cb14b5b76028156b
4
+ data.tar.gz: ed1ca477399d53439683414a943e99ba727dd07ebb7f4a7229db7bd106e74b5c
5
5
  SHA512:
6
- metadata.gz: 6724d7e8ee142b43534ca17fd53d729272d83ab0f6e5f3ef0cf1b07ac63a552bc8393a167b1d6f324cf809fd27bb88f6379375929f130481a16b1ef69f24068e
7
- data.tar.gz: 800fa36240abe3b85afc58951efa01c519fa6802d74d9fe92a67eb5719e3d25dfc2348f6d38dc347be7ccf9d6c7c1a6e4f4ca92d3117c04775a67ed151295a3e
6
+ metadata.gz: e211f819f4d54ad740f422902c98ea9086c1b02e738aa4907a7fcd79841a42ad3478f37c72d6399208be06bac0567c61c08652a50b492e9bcfc774600f056a88
7
+ data.tar.gz: 286a48bb42872720a371e48fc5f872456af7c1a0d655bfe677554a3eef459cbe8309bc974e0ef4f38fd8b434026f078828b99a5efb86e9b197dd9d7b68d42bad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waylon-core (0.1.9)
4
+ waylon-core (0.2.2)
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
54
  multipart-post (2.2.3)
54
- mustermann (1.1.1)
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/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.storage = 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
@@ -1,14 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Waylon::Cache = Moneta.new(
4
- :Redis,
5
- url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1"
6
- )
7
-
8
3
  module Waylon
9
4
  # Used for working with the Moneta store
10
5
  module Storage
11
- Store = Moneta.new(
6
+ DefaultStorage = Moneta.new(
12
7
  :Redis,
13
8
  url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/2"
14
9
  )
@@ -19,16 +14,20 @@ module Waylon
19
14
  end
20
15
 
21
16
  def self.clear
22
- Store.clear
17
+ storage.clear
18
+ end
19
+
20
+ def self.delete(key)
21
+ storage.delete(key)
23
22
  end
24
23
 
25
24
  def self.key?(name)
26
- Store.key?(name)
25
+ storage.key?(name)
27
26
  end
28
27
 
29
28
  def self.load(key)
30
29
  this_cipher = cipher
31
- raw = Store.load(key)
30
+ raw = storage.load(key)
32
31
  return nil unless raw
33
32
 
34
33
  decoded = Base64.decode64(raw)
@@ -36,11 +35,19 @@ module Waylon
36
35
  JSON.parse(plain)
37
36
  end
38
37
 
38
+ def self.storage
39
+ @storage ||= DefaultStorage
40
+ end
41
+
42
+ def self.storage=(storage)
43
+ @storage = storage
44
+ end
45
+
39
46
  def self.store(key, value)
40
47
  this_cipher = cipher
41
48
  encrypted = this_cipher.encrypt(value.to_json)
42
49
  encoded = Base64.encode64(encrypted)
43
- Store.store(key, encoded)
50
+ storage.store(key, encoded)
44
51
  end
45
52
  end
46
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
- 9 # Patch
8
+ 2, # Minor
9
+ 2 # 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.9
4
+ version: 0.2.2
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-19 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