http_store 0.3.25 → 0.5.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: 8ea5b823d0827eb5eab4f525425f1b40ae92e738ce5051f82a1194ef93109af2
4
- data.tar.gz: 96cda715cd019a616638462a049c2f98c40ae25a2fc9c623377e4de1357ff72e
3
+ metadata.gz: c3d99fb3eccde52a754bdc4a0a83ff650591c297f28dcc9d8eccc0e24ef0c4b0
4
+ data.tar.gz: f597d1f6ef335f2da23cf95d62c7d8f07b23001d5ef07e46c89d8a8fb8a0564c
5
5
  SHA512:
6
- metadata.gz: 1309b79c2849852c398ec5213cc3bdf4969f7896410547fd50f6993a10e56ca15df8b5a666dbf9abcb7956834c115f350266221044803fdc9f7535cad02b8980
7
- data.tar.gz: 478086a9d32bb0fe9925459d9bf00428aaa6a59dd234fa58ab675c467f98aa57b184c02b58a09a1de35fe8647f64904daf40315f21239f8808f9256467915635
6
+ metadata.gz: 0f05f4b6a7087861b78e83e76f67eca620f544a0a3677afe177b7b6bb1144701f2570681dbbde9452bcd0331472c5e7cdec2d356662da737bc456a336a77bab6
7
+ data.tar.gz: 22b94e98bfea7fb0a64e79befe7888e2e9721a79c1b32ac14c82b4a8550facba6727672cc0aeba99c00d187903017c470b14540a1d3f8fdf3a2e619e49ac82da
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http_store (0.3.25)
4
+ http_store (0.5.2)
5
5
  activerecord (>= 5.0, < 6.1)
6
6
  hashie (~> 3.0)
7
7
  rails (>= 5, < 7)
@@ -10,110 +10,125 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (5.2.3)
14
- actionpack (= 5.2.3)
13
+ actioncable (6.0.3.3)
14
+ actionpack (= 6.0.3.3)
15
15
  nio4r (~> 2.0)
16
16
  websocket-driver (>= 0.6.1)
17
- actionmailer (5.2.3)
18
- actionpack (= 5.2.3)
19
- actionview (= 5.2.3)
20
- activejob (= 5.2.3)
17
+ actionmailbox (6.0.3.3)
18
+ actionpack (= 6.0.3.3)
19
+ activejob (= 6.0.3.3)
20
+ activerecord (= 6.0.3.3)
21
+ activestorage (= 6.0.3.3)
22
+ activesupport (= 6.0.3.3)
23
+ mail (>= 2.7.1)
24
+ actionmailer (6.0.3.3)
25
+ actionpack (= 6.0.3.3)
26
+ actionview (= 6.0.3.3)
27
+ activejob (= 6.0.3.3)
21
28
  mail (~> 2.5, >= 2.5.4)
22
29
  rails-dom-testing (~> 2.0)
23
- actionpack (5.2.3)
24
- actionview (= 5.2.3)
25
- activesupport (= 5.2.3)
26
- rack (~> 2.0)
30
+ actionpack (6.0.3.3)
31
+ actionview (= 6.0.3.3)
32
+ activesupport (= 6.0.3.3)
33
+ rack (~> 2.0, >= 2.0.8)
27
34
  rack-test (>= 0.6.3)
28
35
  rails-dom-testing (~> 2.0)
29
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- actionview (5.2.3)
31
- activesupport (= 5.2.3)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.0.3.3)
38
+ actionpack (= 6.0.3.3)
39
+ activerecord (= 6.0.3.3)
40
+ activestorage (= 6.0.3.3)
41
+ activesupport (= 6.0.3.3)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.0.3.3)
44
+ activesupport (= 6.0.3.3)
32
45
  builder (~> 3.1)
33
46
  erubi (~> 1.4)
34
47
  rails-dom-testing (~> 2.0)
35
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
- activejob (5.2.3)
37
- activesupport (= 5.2.3)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ activejob (6.0.3.3)
50
+ activesupport (= 6.0.3.3)
38
51
  globalid (>= 0.3.6)
39
- activemodel (5.2.3)
40
- activesupport (= 5.2.3)
41
- activerecord (5.2.3)
42
- activemodel (= 5.2.3)
43
- activesupport (= 5.2.3)
44
- arel (>= 9.0)
45
- activestorage (5.2.3)
46
- actionpack (= 5.2.3)
47
- activerecord (= 5.2.3)
52
+ activemodel (6.0.3.3)
53
+ activesupport (= 6.0.3.3)
54
+ activerecord (6.0.3.3)
55
+ activemodel (= 6.0.3.3)
56
+ activesupport (= 6.0.3.3)
57
+ activestorage (6.0.3.3)
58
+ actionpack (= 6.0.3.3)
59
+ activejob (= 6.0.3.3)
60
+ activerecord (= 6.0.3.3)
48
61
  marcel (~> 0.3.1)
49
- activesupport (5.2.3)
62
+ activesupport (6.0.3.3)
50
63
  concurrent-ruby (~> 1.0, >= 1.0.2)
51
64
  i18n (>= 0.7, < 2)
52
65
  minitest (~> 5.1)
53
66
  tzinfo (~> 1.1)
54
- arel (9.0.0)
55
- builder (3.2.3)
67
+ zeitwerk (~> 2.2, >= 2.2.2)
68
+ builder (3.2.4)
56
69
  byebug (11.0.1)
57
- concurrent-ruby (1.1.5)
58
- crass (1.0.4)
70
+ concurrent-ruby (1.1.7)
71
+ crass (1.0.6)
59
72
  diff-lcs (1.3)
60
73
  domain_name (0.5.20190701)
61
74
  unf (>= 0.0.5, < 1.0.0)
62
- erubi (1.8.0)
75
+ erubi (1.9.0)
63
76
  globalid (0.4.2)
64
77
  activesupport (>= 4.2.0)
65
78
  hashie (3.6.0)
66
79
  http-accept (1.7.0)
67
80
  http-cookie (1.0.3)
68
81
  domain_name (~> 0.5)
69
- i18n (1.6.0)
82
+ i18n (1.8.5)
70
83
  concurrent-ruby (~> 1.0)
71
- loofah (2.2.3)
84
+ loofah (2.7.0)
72
85
  crass (~> 1.0.2)
73
86
  nokogiri (>= 1.5.9)
74
87
  mail (2.7.1)
75
88
  mini_mime (>= 0.1.1)
76
89
  marcel (0.3.3)
77
90
  mimemagic (~> 0.3.2)
78
- method_source (0.9.2)
79
- mime-types (3.3)
91
+ method_source (1.0.0)
92
+ mime-types (3.3.1)
80
93
  mime-types-data (~> 3.2015)
81
- mime-types-data (3.2019.1009)
82
- mimemagic (0.3.3)
94
+ mime-types-data (3.2020.0512)
95
+ mimemagic (0.3.5)
83
96
  mini_mime (1.0.2)
84
97
  mini_portile2 (2.4.0)
85
- minitest (5.11.3)
98
+ minitest (5.14.2)
86
99
  netrc (0.11.0)
87
- nio4r (2.5.1)
88
- nokogiri (1.10.4)
100
+ nio4r (2.5.4)
101
+ nokogiri (1.10.10)
89
102
  mini_portile2 (~> 2.4.0)
90
- rack (2.0.7)
103
+ rack (2.2.3)
91
104
  rack-test (1.1.0)
92
105
  rack (>= 1.0, < 3)
93
- rails (5.2.3)
94
- actioncable (= 5.2.3)
95
- actionmailer (= 5.2.3)
96
- actionpack (= 5.2.3)
97
- actionview (= 5.2.3)
98
- activejob (= 5.2.3)
99
- activemodel (= 5.2.3)
100
- activerecord (= 5.2.3)
101
- activestorage (= 5.2.3)
102
- activesupport (= 5.2.3)
106
+ rails (6.0.3.3)
107
+ actioncable (= 6.0.3.3)
108
+ actionmailbox (= 6.0.3.3)
109
+ actionmailer (= 6.0.3.3)
110
+ actionpack (= 6.0.3.3)
111
+ actiontext (= 6.0.3.3)
112
+ actionview (= 6.0.3.3)
113
+ activejob (= 6.0.3.3)
114
+ activemodel (= 6.0.3.3)
115
+ activerecord (= 6.0.3.3)
116
+ activestorage (= 6.0.3.3)
117
+ activesupport (= 6.0.3.3)
103
118
  bundler (>= 1.3.0)
104
- railties (= 5.2.3)
119
+ railties (= 6.0.3.3)
105
120
  sprockets-rails (>= 2.0.0)
106
121
  rails-dom-testing (2.0.3)
107
122
  activesupport (>= 4.2.0)
108
123
  nokogiri (>= 1.6)
109
- rails-html-sanitizer (1.2.0)
110
- loofah (~> 2.2, >= 2.2.2)
111
- railties (5.2.3)
112
- actionpack (= 5.2.3)
113
- activesupport (= 5.2.3)
124
+ rails-html-sanitizer (1.3.0)
125
+ loofah (~> 2.3)
126
+ railties (6.0.3.3)
127
+ actionpack (= 6.0.3.3)
128
+ activesupport (= 6.0.3.3)
114
129
  method_source
115
130
  rake (>= 0.8.7)
116
- thor (>= 0.19.0, < 2.0)
131
+ thor (>= 0.20.3, < 2.0)
117
132
  rake (10.5.0)
118
133
  rest-client (2.1.0)
119
134
  http-accept (>= 1.7.0, < 2.0)
@@ -133,23 +148,24 @@ GEM
133
148
  diff-lcs (>= 1.2.0, < 2.0)
134
149
  rspec-support (~> 3.8.0)
135
150
  rspec-support (3.8.2)
136
- sprockets (3.7.2)
151
+ sprockets (4.0.2)
137
152
  concurrent-ruby (~> 1.0)
138
153
  rack (> 1, < 3)
139
- sprockets-rails (3.2.1)
154
+ sprockets-rails (3.2.2)
140
155
  actionpack (>= 4.0)
141
156
  activesupport (>= 4.0)
142
157
  sprockets (>= 3.0.0)
143
- thor (0.20.3)
158
+ thor (1.0.1)
144
159
  thread_safe (0.3.6)
145
- tzinfo (1.2.5)
160
+ tzinfo (1.2.7)
146
161
  thread_safe (~> 0.1)
147
162
  unf (0.1.4)
148
163
  unf_ext
149
- unf_ext (0.0.7.6)
150
- websocket-driver (0.7.1)
164
+ unf_ext (0.0.7.7)
165
+ websocket-driver (0.7.3)
151
166
  websocket-extensions (>= 0.1.0)
152
- websocket-extensions (0.1.4)
167
+ websocket-extensions (0.1.5)
168
+ zeitwerk (2.4.0)
153
169
 
154
170
  PLATFORMS
155
171
  ruby
@@ -162,4 +178,4 @@ DEPENDENCIES
162
178
  rspec (~> 3.0)
163
179
 
164
180
  BUNDLED WITH
165
- 2.0.2
181
+ 2.1.4
@@ -0,0 +1,5 @@
1
+ class AddRetryTimesFieldToHttpLog < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :http_logs, :retry_times, :integer
4
+ end
5
+ end
@@ -8,7 +8,7 @@ require 'http_store/engine'
8
8
  module HttpStore
9
9
  extend ActiveSupport::Autoload
10
10
 
11
- REQUEST_KEYS = %w[http_method url data_type headers query_params data other_params force request_valid]
11
+ REQUEST_KEYS = %w[http_method url data_type headers query_params data other_params force request_valid retry_times]
12
12
  RESPONSE_KEYS = %w[status_code response response_headers response_data response_valid response_code cache_response]
13
13
  META_KEYS = %w[request_digest client_type parent_id requestable_id requestable_type]
14
14
  TMP_KEYS = %w[requestable response_obj]
@@ -15,17 +15,19 @@ module HttpStore
15
15
  build_request
16
16
 
17
17
  return unless request_valid?
18
-
19
- # exist request or not force, return
20
18
  load_storeable_record and return if use_cache?
21
19
 
22
20
  execute # send request
23
- raise HttpStore::RequestError, 'response_obj is nil' if response_obj.nil?
21
+ retry! while need_retry? && retry_times.to_i > 0
24
22
 
25
- build_response
26
23
  after_response
27
- ensure
28
- store_request
24
+ end
25
+
26
+ def retry!
27
+ @meta.retry_times = retry_times.to_i - 1
28
+ @meta.force = true
29
+
30
+ execute
29
31
  end
30
32
 
31
33
  HttpStore::ALL_KEYS.each do |meta_key|
@@ -47,6 +49,11 @@ module HttpStore
47
49
 
48
50
  def execute
49
51
  @meta.response_obj = get? ? http_get_execute : http_post_execute
52
+ raise HttpStore::RequestError, 'response_obj is nil' if response_obj.nil?
53
+
54
+ build_response
55
+ ensure
56
+ store_request
50
57
  end
51
58
 
52
59
  def http_get_execute
@@ -9,5 +9,9 @@ module HttpStore
9
9
  def store_class
10
10
  @store_class || HttpStore::HttpLog
11
11
  end
12
+
13
+ def store_time
14
+ @store_time || 31_536_000
15
+ end
12
16
  end
13
17
  end
@@ -6,6 +6,10 @@ module HttpStore
6
6
  status_code >= 200 && status_code < 400
7
7
  end
8
8
 
9
+ def need_retry?
10
+ !response_valid?
11
+ end
12
+
9
13
  def json_response?
10
14
  response_headers_hash['content_type'].to_s =~ /json/
11
15
  end
@@ -1,12 +1,14 @@
1
1
  module HttpStore
2
2
  module Helpers
3
3
  module Storable
4
- STRING_LIMIT_SIZE = 30_000
4
+ STRING_LIMIT_SIZE = 1000
5
+ TEXT_LIMIT_SIZE = 10000
5
6
 
6
7
  def storeable_record
7
8
  return unless HttpStore.config.store_enable
8
9
 
9
- @storeable_record ||= HttpStore.config.store_class.where(request_digest: @meta.request_digest, cache_response: true).order(id: :desc).first
10
+ expired_time = Time.current - HttpStore.config.store_time
11
+ @storeable_record ||= HttpStore.config.store_class.where('created_at > ?', expired_time).where(request_digest: @meta.request_digest, cache_response: true).order(id: :desc).first
10
12
  end
11
13
 
12
14
  def load_storeable_record
@@ -28,15 +30,6 @@ module HttpStore
28
30
  @meta.parent_id = storeable_record.id if use_cache?
29
31
  @storeable_record = HttpStore.config.store_class.new(gen_storable_meta)
30
32
  @storeable_record.save!
31
- rescue ActiveRecord::StatementInvalid
32
-
33
- Rails.logger.info(@storeable_record.response)
34
- Rails.logger.info(@storeable_record.response.encoding)
35
- Rails.logger.info(@storeable_record.response.first.encoding)
36
- Rails.logger.info('xxx' * 2000)
37
-
38
- @storeable_record.response = Digest::SHA1.hexdigest(@storeable_record.response)
39
- @storeable_record.save!
40
33
  end
41
34
 
42
35
  def use_cache?
@@ -48,11 +41,11 @@ module HttpStore
48
41
  storable_v = storable(v)
49
42
 
50
43
  begin
51
- storable_v = storable_v.to_json[0..STRING_LIMIT_SIZE] if v.is_a?(Hash) || v.is_a?(Array)
44
+ storable_v = storable_v.to_json[0..TEXT_LIMIT_SIZE] if v.is_a?(Hash) || v.is_a?(Array)
52
45
 
53
46
  [k, storable_v]
54
47
  rescue JSON::GeneratorError
55
- [k, storable_v.to_s[0..STRING_LIMIT_SIZE]]
48
+ [k, storable_v.to_s[0..TEXT_LIMIT_SIZE]]
56
49
  end
57
50
  end.to_h
58
51
  end
@@ -78,7 +71,7 @@ module HttpStore
78
71
  raise EncodingError unless str.encoding.name == 'UTF-8'
79
72
  raise EncodingError unless str.valid_encoding?
80
73
 
81
- str.length > STRING_LIMIT_SIZE ? { digest: Digest::SHA1.hexdigest(str), origin: str[0..1000] } : str
74
+ str.length > STRING_LIMIT_SIZE ? { digest: Digest::SHA1.hexdigest(str), origin: str[0..STRING_LIMIT_SIZE] } : str
82
75
  rescue EncodingError
83
76
  { digest: Digest::SHA1.hexdigest(str) }
84
77
  end
@@ -1,3 +1,3 @@
1
1
  module HttpStore
2
- VERSION = "0.3.25"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.25
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - black
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -153,6 +153,7 @@ files:
153
153
  - bin/setup
154
154
  - db/migrate/1_create_http_logs.rb
155
155
  - db/migrate/2_add_cache_response_field_to_http_log.rb
156
+ - db/migrate/3_add_retry_times_field_to_http_log.rb
156
157
  - http_store.gemspec
157
158
  - lib/generators/http_store/initializer_generator.rb
158
159
  - lib/http_store.rb
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  - !ruby/object:Gem::Version
187
188
  version: '0'
188
189
  requirements: []
189
- rubygems_version: 3.0.4
190
+ rubygems_version: 3.0.8
190
191
  signing_key:
191
192
  specification_version: 4
192
193
  summary: store the http request, it based on rest-client