jpsclient 1.7.0 → 1.8.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: fc2afd23d09740af2160dbbfc2c6c1f0cffb937b5da3ab905c29582d0738eeb1
4
- data.tar.gz: 6dacc82e06e921343226aca9a2277ea7a5a6f2c43f949fc46f4cbdc5136ba1ad
3
+ metadata.gz: 964eac6cd5b6f4c45e0dc0533a7a2bd68eb1363132b25314e394f5234a09d978
4
+ data.tar.gz: 70124f395973eddec1d62e66230ad9584c2ab841d14ac8f99ddf903fb88505a7
5
5
  SHA512:
6
- metadata.gz: b9b0002b6139c3b5d83dc4afcb9d4c185e4009205845db11fecbc06429cf4b588d7557bf71f1a648465f20532e2915f3d3a3939b4fec6209b6b57f862f4715b6
7
- data.tar.gz: 0ab8ae8afd9e9db0a5a508a8ce2c4a6f2ba5552906506f05168ac6d053140ffda61f62c15d7de8599438d9b62c03d63018a8aa98940ede6e7921201ffc0aadb0
6
+ metadata.gz: aae1920afcce6295fd8589d9b8c6d91186dab110b58883de449ab467ea27c553bdee976b3d03145a152b82e1bd4327110135ab87b536f59c90b6f312093b9f16
7
+ data.tar.gz: 249f21c49c4838fdbafce3b5047aa97215f94caff834dde2c0ca4ba3fb75eb22d2eaeaafc7cd7bc6de4119ea86597a3646d65cc91840c1b3ddf79ff611cc8ffa
@@ -42,7 +42,8 @@ module JPSClient
42
42
  # @param workflowId [Integer] 工作流ID(必需)
43
43
  # @param params [Hash] 其他参数
44
44
  # @option params [Boolean] :single 是否单个提交(默认 true)
45
- # @option params [Array<String>] :branches 分支名称数组
45
+ # @option params [String] :branch 分支名称(单数形式)
46
+ # @option params [Array<String>] :branches 分支名称数组(向后兼容)
46
47
  # @option params [Array<String>] :commitIds 提交ID数组
47
48
  # @option params [Integer] :startTimestamp 开始时间戳
48
49
  # @option params [Integer] :endTimestamp 结束时间戳
@@ -60,7 +61,8 @@ module JPSClient
60
61
  }
61
62
 
62
63
  # 添加可选参数
63
- body_params[:branches] = params[:branches] if params[:branches]
64
+ body_params[:branch] = params[:branch] if params[:branch] # 支持单数形式
65
+ body_params[:branches] = params[:branches] if params[:branches] # 向后兼容复数形式
64
66
  body_params[:commitIds] = params[:commitIds] if params[:commitIds]
65
67
  body_params[:startTimestamp] = params[:startTimestamp] if params[:startTimestamp]
66
68
  body_params[:endTimestamp] = params[:endTimestamp] if params[:endTimestamp]
@@ -1,8 +1,77 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
- require 'faraday/retry'
3
+ require 'typhoeus'
4
+ require 'typhoeus/adapters/faraday'
4
5
 
5
6
  module JPSClient
7
+ # 简单的 Faraday 重试中间件(替代 faraday-retry)
8
+ class SimpleRetryMiddleware < Faraday::Middleware
9
+ # 默认幂等的 HTTP 方法(可安全重试)
10
+ IDEMPOTENT_METHODS = [:get, :head, :put, :delete, :options, :trace].freeze
11
+ # 可重试的 HTTP 状态码(5xx 服务器错误)
12
+ RETRIABLE_STATUS_CODES = (500..599).freeze
13
+
14
+ def initialize(app, options = {})
15
+ super(app)
16
+ @max = options[:max] || 3 # 最大重试次数(不包括首次尝试)
17
+ @interval = options[:interval] || 0.5
18
+ @backoff_factor = options[:backoff_factor] || 2
19
+ @interval_randomness = options[:interval_randomness] || 0.5
20
+ @exceptions = options[:exceptions] || [Faraday::TimeoutError, Faraday::ConnectionFailed]
21
+ @methods = options[:methods] || IDEMPOTENT_METHODS # 允许重试的 HTTP 方法
22
+ @retry_statuses = options[:retry_statuses] || RETRIABLE_STATUS_CODES
23
+ end
24
+
25
+ def call(env)
26
+ retries = 0
27
+
28
+ loop do
29
+ begin
30
+ response = @app.call(env)
31
+
32
+ # 检查 HTTP 状态码是否需要重试(5xx 错误)
33
+ # 同时必须满足幂等性要求,避免非幂等请求(如 POST)被意外重试
34
+ if retriable_response?(response) && retriable_request?(env) && retries < @max
35
+ retries += 1
36
+ sleep_with_jitter(retries)
37
+ next # 继续下一次循环(重试)
38
+ end
39
+
40
+ return response # 成功,返回响应
41
+
42
+ rescue *@exceptions => e
43
+ # 检查是否为幂等方法,非幂等方法不自动重试
44
+ if retriable_request?(env) && retries < @max
45
+ retries += 1
46
+ sleep_with_jitter(retries)
47
+ next # 继续下一次循环(重试)
48
+ else
49
+ raise e # 不能重试,抛出异常
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # 检查请求是否可重试(幂等性检查)
58
+ def retriable_request?(env)
59
+ @methods.include?(env[:method])
60
+ end
61
+
62
+ # 检查响应是否需要重试(5xx 状态码)
63
+ def retriable_response?(response)
64
+ @retry_statuses.include?(response.status)
65
+ end
66
+
67
+ # 指数退避 + 随机抖动
68
+ def sleep_with_jitter(retry_count)
69
+ sleep_time = @interval * (@backoff_factor ** (retry_count - 1))
70
+ jitter = rand * sleep_time * @interval_randomness
71
+ sleep(sleep_time + jitter)
72
+ end
73
+ end
74
+
6
75
  # JPS 专用 HTTP 客户端 - 优化版
7
76
  class HttpClient
8
77
  attr_accessor :base_url
@@ -93,8 +162,8 @@ module JPSClient
93
162
  # 获取或创建连接(复用连接)
94
163
  def connection
95
164
  @connection ||= Faraday.new do |config|
96
- # 重试配置
97
- config.request :retry, {
165
+ # 使用自定义重试中间件(替代 faraday-retry)
166
+ config.use SimpleRetryMiddleware, {
98
167
  max: @max_retry_times,
99
168
  interval: 0.5,
100
169
  backoff_factor: 2,
@@ -111,7 +180,8 @@ module JPSClient
111
180
  }.compact
112
181
  end
113
182
 
114
- config.adapter Faraday.default_adapter
183
+ # 使用 Typhoeus 适配器(高性能 HTTP 客户端)
184
+ config.adapter :typhoeus
115
185
  end
116
186
  end
117
187
 
@@ -5,8 +5,6 @@ module JPSClient
5
5
  class UploadConfig
6
6
  attr_accessor :region
7
7
  attr_accessor :bucket_name
8
- attr_accessor :access_key_id
9
- attr_accessor :access_key_secret
10
8
  attr_accessor :default_url
11
9
  attr_accessor :attach_url
12
10
  attr_accessor :upload_type # 上传类型
@@ -21,8 +19,6 @@ module JPSClient
21
19
  def initialize(
22
20
  region: nil,
23
21
  bucket_name: nil,
24
- access_key_id: nil,
25
- access_key_secret: nil,
26
22
  default_url: nil,
27
23
  attach_url: nil,
28
24
  upload_type: nil,
@@ -36,8 +32,6 @@ module JPSClient
36
32
  )
37
33
  @region = region
38
34
  @bucket_name = bucket_name
39
- @access_key_id = access_key_id
40
- @access_key_secret = access_key_secret
41
35
  @default_url = default_url
42
36
  @attach_url = attach_url
43
37
  @upload_type = upload_type
@@ -60,8 +54,6 @@ module JPSClient
60
54
  new(
61
55
  region: json_config['region'] || "ap-southeast-1",
62
56
  bucket_name: json_config['bucket_name'] || "pgy-resource-new",
63
- access_key_id: json_config['access_key_id'],
64
- access_key_secret: json_config['access_key_secret'],
65
57
  default_url: json_config['default_url'] || "resource/",
66
58
  attach_url: json_config['attach_url'] || "attach_file/",
67
59
  upload_type: json_config['upload_type'] || "s3",
@@ -114,9 +106,11 @@ module JPSClient
114
106
  end
115
107
 
116
108
  # 验证配置完整性
109
+ # 注意:移除了对 access_key_id 和 access_key_secret 的验证
110
+ # 因为客户端使用预签名 URL,不直接使用 AWS 凭证
111
+ # AWS 凭证由 JPS 服务器端管理
117
112
  def valid?
118
113
  !@region.nil? && !@bucket_name.nil? &&
119
- !@access_key_id.nil? && !@access_key_secret.nil? &&
120
114
  !@default_url.nil? && !@attach_url.nil?
121
115
  end
122
116
 
@@ -130,8 +124,6 @@ module JPSClient
130
124
  {
131
125
  'region' => @region,
132
126
  'bucket_name' => @bucket_name,
133
- 'access_key_id' => @access_key_id,
134
- 'access_key_secret' => @access_key_secret,
135
127
  'default_url' => @default_url,
136
128
  'attach_url' => @attach_url,
137
129
  'upload_type' => @upload_type,
@@ -1,3 +1,3 @@
1
1
  module JPSClient
2
- VERSION = "1.7.0"
2
+ VERSION = "1.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpsclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name
@@ -29,26 +29,6 @@ dependencies:
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '3.0'
32
- - !ruby/object:Gem::Dependency
33
- name: faraday-retry
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - ">="
37
- - !ruby/object:Gem::Version
38
- version: '1.0'
39
- - - "<"
40
- - !ruby/object:Gem::Version
41
- version: '3.0'
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '1.0'
49
- - - "<"
50
- - !ruby/object:Gem::Version
51
- version: '3.0'
52
32
  - !ruby/object:Gem::Dependency
53
33
  name: typhoeus
54
34
  requirement: !ruby/object:Gem::Requirement
@@ -303,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
283
  - !ruby/object:Gem::Version
304
284
  version: '0'
305
285
  requirements: []
306
- rubygems_version: 3.6.9
286
+ rubygems_version: 4.0.3
307
287
  specification_version: 4
308
288
  summary: JPS Platform API Client with Full API Support
309
289
  test_files: []