zaikio-jwt_auth 0.5.1 → 1.0.0

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: cbd7c7fb4d5cb2a3d1001e5a24036beafbf3dcf76200bd052ee4c1d731c39a2d
4
- data.tar.gz: 94a597d69c55f1dee78784967f6b6fa33d0b3aee98d55b4001060bc28ad1cf97
3
+ metadata.gz: 5246d95da7085c56dce3719ba3bdba4c102c3b4dd01c941cacb5de5d9e813eb0
4
+ data.tar.gz: 354e97d2ef3972049e103fa0afea9e047f9990ab816ca8b7afec7c3671e0d90b
5
5
  SHA512:
6
- metadata.gz: 6be2c8d3b1000c4dcbe09518fc4afb38a6f550fced5dfb82eca44636755adbcc50897c8ed81729346f8ab2b3838b2a033a0c6b33a7cb37d3e2027644e2e2daad
7
- data.tar.gz: 370e9de4ce7973de106fb66259d43186876591770f71e819448d386d5c64f17751ebb32573130533777a4477df6cd0b93997e4fb6de5f7418ef4f2c82d22d560
6
+ metadata.gz: 8025ca7934fac9df869afde1fd23287208fb9edbd1970e3d065d9591062a1557a435f6cb0d7d8147d8f8f2fdbb476ae00dead2d89bb232951489de785df0e248
7
+ data.tar.gz: 89431f5cdf4ad50dff018a35530fb95d97d2a9a91a1908566b8d9de187dff65f1203bfb76a7eef79fcc3fca116f336ab194c18b8bd583d830098481678a53aa8
@@ -5,6 +5,13 @@ require "logger"
5
5
  module Zaikio
6
6
  module JWTAuth
7
7
  class DirectoryCache
8
+ class UpdateJob < ::ActiveJob::Base
9
+ def perform(directory_path)
10
+ DirectoryCache.fetch(directory_path)
11
+ true # This job will always re-queue until it succeeds.
12
+ end
13
+ end
14
+
8
15
  BadResponseError = Class.new(StandardError)
9
16
 
10
17
  class << self
@@ -14,7 +21,8 @@ module Zaikio
14
21
  json = Oj.load(cache) if cache
15
22
 
16
23
  if !cache || options[:invalidate] || cache_expired?(json, options[:expires_after])
17
- return reload(directory_path)
24
+ new_values = reload_or_enqueue(directory_path)
25
+ return new_values || json["data"]
18
26
  end
19
27
 
20
28
  json["data"]
@@ -39,24 +47,18 @@ module Zaikio
39
47
  DateTime.strptime(json["fetched_at"].to_s, "%s") < Time.now.utc - (expires_after || 1.hour)
40
48
  end
41
49
 
42
- def reload(directory_path)
43
- retries = 0
44
-
45
- begin
46
- data = fetch_from_directory(directory_path)
47
- Zaikio::JWTAuth.configuration.redis.set("zaikio::jwt_auth::#{directory_path}", {
48
- fetched_at: Time.now.to_i,
49
- data: data
50
- }.to_json)
51
-
52
- data
53
- rescue Errno::ECONNREFUSED, Net::ReadTimeout, BadResponseError => e
54
- raise unless (retries += 1) <= 3
50
+ def reload_or_enqueue(directory_path)
51
+ data = fetch_from_directory(directory_path)
52
+ Zaikio::JWTAuth.configuration.redis.set("zaikio::jwt_auth::#{directory_path}", {
53
+ fetched_at: Time.now.to_i,
54
+ data: data
55
+ }.to_json)
55
56
 
56
- Zaikio::JWTAuth.configuration.logger.info("Timeout (#{e}), retrying in 1 second...")
57
- sleep(1)
58
- retry
59
- end
57
+ data
58
+ rescue Errno::ECONNREFUSED, Net::ReadTimeout, BadResponseError
59
+ Zaikio::JWTAuth.configuration.logger.info("Error updating DirectoryCache(#{directory_path}), enqueueing job to update")
60
+ UpdateJob.set(wait: 10.seconds).perform_later(directory_path)
61
+ nil
60
62
  end
61
63
 
62
64
  def fetch_from_directory(directory_path)
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module JWTAuth
3
- VERSION = "0.5.1".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-jwt_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-22 00:00:00.000000000 Z
13
+ date: 2021-04-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: oj