jekyll-hackclub 1.5.1 → 1.5.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/server-bridge.rb +33 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 946c0c6e84743e07d73f28be93196ab5b36f64aac96b6b38c874f2f312b64bcd
4
- data.tar.gz: e1042a102d08ca8591bfd7ea152d1ff5b3603257372c301bd94d9d224e834417
3
+ metadata.gz: 5d49c6c3dffd7091a3d90afa44de41199e91f21f2d31fac0c6597b671e11bb56
4
+ data.tar.gz: a4d165bb7ba68d396b591ae8cb1e56720bd14530030daa74bfc53e34494cb750
5
5
  SHA512:
6
- metadata.gz: c93c3636b08e11618087f9927dee95e724721b7ff2675e7868c6da030a863a0e8bff1c9803d1cc8ac0d16bb93c85228c80bf30ea3ac41f74ccf3c0cbdd6ac2c0
7
- data.tar.gz: d44840b14ac1712cb1d1469287d3e6b9a64984c4ef22731654dfae51ea806330c7ef0fa535b5559af236cba1c6e8f162a5dfdeccc8e2da925037129074189171
6
+ metadata.gz: 77ce124b786ace36b4e62ae916d53ba318c6c1511f9516a3774e26f9e914e47696d8cb0096eb3f0cd90740223b91303c974f16b9e992ad2f854653501471b588
7
+ data.tar.gz: 71a709072086f7c47fd02d4f3f83085ac64ac4de354a1964f771680a898b51dc38c0a35d046f23ba17ad3a38fc7565651a75e9caff34183441536d59c547df6e
data/lib/server-bridge.rb CHANGED
@@ -3,27 +3,49 @@ require "json"
3
3
  require "uri"
4
4
 
5
5
  module HackclubRequest
6
- DEFAULT_EMOJI = "https://emoji.slack-edge.com/T0266FRGM/alibaba-question/c5ba32ce553206b8.png" # :alibaba-question:
6
+ DEFAULT_EMOJI = "https://cdn.hackclub.com/019ce841-fe66-72e6-bb16-d57a93ac574f/alibaba-question.png" # :alibaba-question:
7
7
  @host = Jekyll.configuration({})['HACKCLUB_API'] || "https://hackclub.mathiasd.fr"
8
+ DEFAULT_RETRIES = 3
9
+ RETRYABLE_STATUS_CODES = [408, 425, 429, 500, 502, 503, 504].freeze
8
10
 
9
11
  class << self
10
12
  attr_accessor :host
11
13
  end
12
14
 
13
- def self.make_request(path)
15
+ def self.make_request(path, retries: DEFAULT_RETRIES, base_delay: 0.25)
14
16
  uri = URI("#{host}#{path}")
15
- req = Net::HTTP::Get.new(uri)
16
- req['Referer'] = "jekyll-hackclub"
17
+ attempts = 0
17
18
 
18
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
19
- http.request(req)
19
+ while attempts < retries
20
+ attempts += 1
21
+
22
+ begin
23
+ req = Net::HTTP::Get.new(uri)
24
+ req['Referer'] = "jekyll-hackclub"
25
+
26
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", open_timeout: 3, read_timeout: 6) do |http|
27
+ http.request(req)
28
+ end
29
+
30
+ if RETRYABLE_STATUS_CODES.include?(res.code.to_i)
31
+ sleep(base_delay * attempts) if attempts < retries
32
+ next
33
+ end
34
+
35
+ return JSON.parse(res.body), res
36
+ rescue JSON::ParserError
37
+ return {}, res
38
+ rescue => e
39
+ if attempts < retries
40
+ sleep(base_delay * attempts)
41
+ next
42
+ end
43
+
44
+ warn "Request to #{uri} failed after #{attempts} attempts: #{e}"
45
+ return {}, nil
46
+ end
20
47
  end
21
48
 
22
- return JSON.parse(res.body), res
23
- rescue JSON::ParserError
24
- return {}, res
25
- rescue => e
26
- warn "Request to #{uri} failed: #{e}"
27
49
  return {}, nil
28
50
  end
29
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hackclub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MathiasDPX