bearcat 1.5.5 → 1.5.7

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
  SHA256:
3
- metadata.gz: 0f45f61beb5bf6de6be81d2addef3e0abc7a5f9542e343091c40f50bde572f40
4
- data.tar.gz: 2e7c146f8c8b42c2311e9fa28c0d4846c4d15335148655b7af883137cd337d4b
3
+ metadata.gz: 8a944f30f69dd137902c99b5810bb29eebbdf48136039160b5259106f722661e
4
+ data.tar.gz: 044c52dc104b65aac858da9f53f44de11ad8ac08a956cd9fdd21fb458a0d6b0f
5
5
  SHA512:
6
- metadata.gz: 76e66a0e528357694ad74e1580f0e04587e511a31849cd7605c5c1c7dac56936828007a8bc1c597017009909759343fd8cbce494a1d26ce081d43724cfe918c8
7
- data.tar.gz: e171e4b69ee814abdd4c6fa8555dc40518538985bea7738b4955a77acb516ce8d21c46acc1c1baadc756329352f7085315d6a4132d8860414dd96fd58eb9cc09
6
+ metadata.gz: a02a9c9a4ff44e03da5a5e3b0de9aefa1565814aeb2ab8d2099d90eaf9388fae9de67118905b3fa4d72ec6684092b1ece95bc68bdd486494d221a2e05ace823f
7
+ data.tar.gz: 0a42a5dfee36522129ad182a88318891de98da90b6f120f269a93ea8f041d72b6482c0a77e711b1c75873356af10ea508c826e497a7c2c78b2b6481ce7e2c8ba
data/bearcat.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |gem|
33
33
 
34
34
  gem.add_dependency "activesupport"
35
35
  gem.add_dependency "footrest", ">= 0.2.2"
36
+ gem.add_dependency "connection_pool", ">= 2.2.0", "< 3.0"
36
37
  end
@@ -85,8 +85,8 @@ module Bearcat
85
85
  rl = config[:rate_limiter] || Bearcat.rate_limiter
86
86
  master_rate_limit = config[:master_rate_limit].present? ? config[:master_rate_limit] : Bearcat.master_rate_limit
87
87
 
88
- if rl.nil? && master_rate_limit.nil? && defined?(Rails) && Rails.env.production?
89
- master_rate_limit = true if defined?(::Sidekiq)
88
+ if rl.nil? && master_rate_limit.nil? && defined?(Rails) && Rails.env.production? && defined?(::Redis) && RedisConnection.configured?("BEARCAT", explicit: false)
89
+ master_rate_limit = true
90
90
  end
91
91
 
92
92
  if rl.nil? && master_rate_limit
@@ -58,11 +58,10 @@ module Bearcat
58
58
  end
59
59
 
60
60
  def redis(&blk)
61
- # TODO Add bearcat-native ConnectionPool instead of relying on application or Sidekiq to do so
62
61
  if @params[:redis]
63
62
  @params[:redis].call(blk)
64
63
  else
65
- ::Sidekiq.redis(&blk)
64
+ ::Bearcat.redis(&blk)
66
65
  end
67
66
  end
68
67
  end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "connection_pool"
4
+ require "redis"
5
+ require "uri"
6
+
7
+ # Adapted from Sidekiq 6.x Implementation
8
+
9
+ module Bearcat
10
+ module RedisConnection
11
+ KNOWN_REDIS_URL_ENVS = %w[REDIS_URL REDISTOGO_URL REDISCLOUD_URL].freeze
12
+
13
+ class << self
14
+ def configured?(prefix, explicit: false)
15
+ determine_redis_provider(prefix: prefix, explicit: true)
16
+ end
17
+
18
+ def create(options = {})
19
+ symbolized_options = options.transform_keys(&:to_sym)
20
+
21
+ if !symbolized_options[:url] && (u = determine_redis_provider(prefix: options[:env_prefix]))
22
+ symbolized_options[:url] = u
23
+ end
24
+
25
+ size = if symbolized_options[:size]
26
+ symbolized_options[:size]
27
+ elsif symbolized_options[:env_prefix] && (v = ENV["#{symbolized_options[:env_prefix]}_REDIS_POOL_SIZE"])
28
+ Integer(v)
29
+ elsif ENV["RAILS_MAX_THREADS"]
30
+ Integer(ENV["RAILS_MAX_THREADS"])
31
+ else
32
+ 5
33
+ end
34
+
35
+ pool_timeout = symbolized_options[:pool_timeout] || 1
36
+
37
+ ConnectionPool.new(timeout: pool_timeout, size: size) do
38
+ namespace = symbolized_options[:namespace]
39
+ client = Redis.new client_opts(symbolized_options)
40
+
41
+ if namespace
42
+ begin
43
+ require "redis/namespace"
44
+ Redis::Namespace.new(namespace, redis: client)
45
+ rescue LoadError
46
+ Rails.logger.error("Your Redis configuration uses the namespace '#{namespace}' but the redis-namespace gem is not included in the Gemfile." \
47
+ "Add the gem to your Gemfile to continue using a namespace. Otherwise, remove the namespace parameter.")
48
+ exit(-127)
49
+ end
50
+ else
51
+ client
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def client_opts(options)
59
+ opts = options.dup
60
+ if opts[:namespace]
61
+ opts.delete(:namespace)
62
+ end
63
+
64
+ if opts[:network_timeout]
65
+ opts[:timeout] = opts[:network_timeout]
66
+ opts.delete(:network_timeout)
67
+ end
68
+
69
+ opts[:reconnect_attempts] ||= 1
70
+
71
+ opts
72
+ end
73
+
74
+ def determine_redis_provider(prefix: nil, explicit: false)
75
+ vars = []
76
+
77
+ if prefix.present?
78
+ if (ptr = ENV["#{prefix}_REDIS_PROVIDER"]).present?
79
+ return ENV[ptr]
80
+ else
81
+ vars.push(*KNOWN_REDIS_URL_ENVS.map { |e| ENV["#{prefix}_#{e}"] })
82
+ end
83
+ end
84
+
85
+ if !explicit || !prefix.present?
86
+ if (ptr = ENV["REDIS_PROVIDER"]).present?
87
+ vars << ptr # Intentionally not a return
88
+ else
89
+ vars.push(*KNOWN_REDIS_URL_ENVS)
90
+ end
91
+ end
92
+
93
+ vars.select!(&:present?)
94
+
95
+ vars.each do |e|
96
+ return ENV[e] if ENV[e].present?
97
+ end
98
+
99
+ nil
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.5.5' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.5.7' unless defined?(Bearcat::VERSION)
3
3
  end
data/lib/bearcat.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bearcat/version'
2
2
  require 'bearcat/client'
3
+ require 'bearcat/redis_connection'
3
4
 
4
5
  module Bearcat
5
6
  class << self
@@ -27,6 +28,7 @@ module Bearcat
27
28
  @max_sleep_seconds ||= 60
28
29
  end
29
30
 
31
+ # @deprecated
30
32
  def master_rate_limit
31
33
  @master_rate_limit ||= false
32
34
  end
@@ -37,5 +39,16 @@ module Bearcat
37
39
  @logger.level = Logger::DEBUG
38
40
  @logger
39
41
  end
42
+
43
+ def redis_pool
44
+ @redis_pool ||= RedisConnection.create(env_prefix: "BEARCAT")
45
+ end
46
+
47
+ def redis
48
+ raise ArgumentError, "requires a block" unless block_given?
49
+ redis_pool.with do |conn|
50
+ yield conn
51
+ end
52
+ end
40
53
  end
41
54
  end
@@ -11,6 +11,7 @@ module Catalogcat
11
11
  key = 'catalogs' if path =~ %r{.*/catalogs}
12
12
  key = 'enrollments' if path =~ %r{.*/enrollments}
13
13
  key = 'order' if path =~ %r{.*/order/[0-9]*}
14
+ key = 'orders' if path =~ %r{.*/orders}
14
15
  key = 'completed_certificates' if path =~ %r{.*/completed_certificates}
15
16
  key = 'user_registrations' if path =~ %r{.*/user_registrations}
16
17
  end
@@ -1,6 +1,10 @@
1
1
  module Catalogcat
2
2
  class Client < Footrest::Client
3
3
  module Certificates
4
+ def listing_certificate(listing_id, params = {})
5
+ get("/api/v1/certificates?certificate[listing_id]=#{listing_id}", params)
6
+ end
7
+
4
8
  def create_certificate(params = {})
5
9
  post('/api/v1/certificates', params)
6
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bearcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-28 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,26 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.2.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: connection_pool
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.2.0
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '3.0'
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 2.2.0
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
125
145
  description: Ruby interface for interacting with the canvas API
126
146
  email:
127
147
  - pseng@instructure.com
@@ -187,6 +207,7 @@ files:
187
207
  - lib/bearcat/rate_limiting/functions.lua
188
208
  - lib/bearcat/rate_limiting/increment_bucket.lua
189
209
  - lib/bearcat/rate_limiting/redis_script.rb
210
+ - lib/bearcat/redis_connection.rb
190
211
  - lib/bearcat/spec_helpers.rb
191
212
  - lib/bearcat/version.rb
192
213
  - lib/catalogcat.rb