hastci 0.1.5 → 0.1.6
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 +4 -4
- data/lib/hastci/api_client.rb +18 -13
- data/lib/hastci/claim_result.rb +2 -11
- data/lib/hastci/task_buffer.rb +2 -1
- data/lib/hastci/version.rb +1 -1
- data/spec/pacts/hastci_rspec-hastci_api.json +2 -21
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91790bf0626d7e4df2d26cc1cefe89371d5bf3080bc56708775a11782f412a62
|
|
4
|
+
data.tar.gz: be0ce4993d12695e2b41f0b57b1860312bd52b86b2bd478973653edb994af2e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4279fb63c5b4ba58d73f94dd342f81611af331a78b69c309d5a912c40361fc0ee4352bdb18b395ef2d7903ac38fd143236f044b34a1dea936d633f3ba214376
|
|
7
|
+
data.tar.gz: eec7921d963ba82888dad00cc7a3a4d93db8e8ec35044a0149aae410330a80d1503ad8d6d17543fe23a9c25826e77e2aeaf76b36a98ca00c35ffde35f84ad449
|
data/lib/hastci/api_client.rb
CHANGED
|
@@ -106,19 +106,7 @@ module HastCI
|
|
|
106
106
|
context: "#{API_PATH_PREFIX}/runs/:run_id/claims"
|
|
107
107
|
)
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
Task.new(
|
|
111
|
-
id: fetch_required(task_data, "id", context: "#{API_PATH_PREFIX}/runs/:run_id/claims"),
|
|
112
|
-
name: fetch_required(task_data, "name", context: "#{API_PATH_PREFIX}/runs/:run_id/claims")
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
ClaimResult.new(
|
|
117
|
-
tasks: tasks,
|
|
118
|
-
queue_state: response["queue_state"]&.to_sym,
|
|
119
|
-
remaining: response["remaining"],
|
|
120
|
-
should_stop: response["should_stop"]
|
|
121
|
-
)
|
|
109
|
+
build_claim_result(response)
|
|
122
110
|
end
|
|
123
111
|
|
|
124
112
|
def ack(task_id:, status:, duration_s:, logs:)
|
|
@@ -142,6 +130,21 @@ module HastCI
|
|
|
142
130
|
|
|
143
131
|
private
|
|
144
132
|
|
|
133
|
+
def build_claim_result(response)
|
|
134
|
+
tasks = Array(response.fetch("tasks", [])).map do |task_data|
|
|
135
|
+
Task.new(
|
|
136
|
+
id: fetch_required(task_data, "id", context: "#{API_PATH_PREFIX}/runs/:run_id/claims"),
|
|
137
|
+
name: fetch_required(task_data, "name", context: "#{API_PATH_PREFIX}/runs/:run_id/claims")
|
|
138
|
+
)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
ClaimResult.new(
|
|
142
|
+
tasks: tasks,
|
|
143
|
+
queue_state: response["queue_state"]&.to_sym,
|
|
144
|
+
remaining: response["remaining"]
|
|
145
|
+
)
|
|
146
|
+
end
|
|
147
|
+
|
|
145
148
|
def get_json(path, pool: CONNECTION_DEFAULT)
|
|
146
149
|
uri = build_uri(path)
|
|
147
150
|
request = @http_class::Get.new(uri)
|
|
@@ -274,6 +277,8 @@ module HastCI
|
|
|
274
277
|
body = response.body
|
|
275
278
|
|
|
276
279
|
case status
|
|
280
|
+
when 409
|
|
281
|
+
raise RunCancelled.new("Run cancelled", status_code: status, response_body: body)
|
|
277
282
|
when 410
|
|
278
283
|
raise QueueDrained.new("Queue drained", status_code: status, response_body: body)
|
|
279
284
|
when 400..499
|
data/lib/hastci/claim_result.rb
CHANGED
|
@@ -2,26 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
module HastCI
|
|
4
4
|
class ClaimResult
|
|
5
|
-
attr_reader :tasks, :queue_state, :remaining
|
|
5
|
+
attr_reader :tasks, :queue_state, :remaining
|
|
6
6
|
|
|
7
|
-
def initialize(tasks:, queue_state:, remaining: nil
|
|
7
|
+
def initialize(tasks:, queue_state:, remaining: nil)
|
|
8
8
|
@tasks = tasks
|
|
9
9
|
@queue_state = queue_state
|
|
10
10
|
@remaining = remaining
|
|
11
|
-
@should_stop = should_stop
|
|
12
11
|
freeze
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
def drained?
|
|
16
|
-
queue_state == :drained
|
|
17
|
-
end
|
|
18
|
-
|
|
19
14
|
def empty?
|
|
20
15
|
tasks.empty?
|
|
21
16
|
end
|
|
22
|
-
|
|
23
|
-
def cancelled?
|
|
24
|
-
should_stop == true
|
|
25
|
-
end
|
|
26
17
|
end
|
|
27
18
|
end
|
data/lib/hastci/task_buffer.rb
CHANGED
|
@@ -133,6 +133,8 @@ module HastCI
|
|
|
133
133
|
@fetcher.call(capacity)
|
|
134
134
|
rescue QueueDrained
|
|
135
135
|
handle_queue_drained
|
|
136
|
+
rescue RunCancelled
|
|
137
|
+
handle_stop_signal
|
|
136
138
|
rescue RetryExhaustedError => e
|
|
137
139
|
handle_fatal_fetch_error(e, "Prefetch failed after retries")
|
|
138
140
|
rescue FatalApiError => e
|
|
@@ -144,7 +146,6 @@ module HastCI
|
|
|
144
146
|
end
|
|
145
147
|
|
|
146
148
|
def process_fetch_result(result, requested_capacity:)
|
|
147
|
-
return handle_stop_signal if result.cancelled?
|
|
148
149
|
return handle_empty_response if result.empty?
|
|
149
150
|
return handle_overflow(result, requested_capacity: requested_capacity) if result.tasks.size > requested_capacity
|
|
150
151
|
|
data/lib/hastci/version.rb
CHANGED
|
@@ -332,31 +332,12 @@
|
|
|
332
332
|
}
|
|
333
333
|
},
|
|
334
334
|
"response": {
|
|
335
|
-
"status":
|
|
335
|
+
"status": 409,
|
|
336
336
|
"headers": {
|
|
337
337
|
"Content-Type": "application/json"
|
|
338
338
|
},
|
|
339
339
|
"body": {
|
|
340
|
-
"
|
|
341
|
-
],
|
|
342
|
-
"queue_state": "cancelled",
|
|
343
|
-
"remaining": {
|
|
344
|
-
"queued": 0,
|
|
345
|
-
"assigned": 0,
|
|
346
|
-
"completed": 5
|
|
347
|
-
},
|
|
348
|
-
"should_stop": true
|
|
349
|
-
},
|
|
350
|
-
"matchingRules": {
|
|
351
|
-
"$.body.remaining.queued": {
|
|
352
|
-
"match": "type"
|
|
353
|
-
},
|
|
354
|
-
"$.body.remaining.assigned": {
|
|
355
|
-
"match": "type"
|
|
356
|
-
},
|
|
357
|
-
"$.body.remaining.completed": {
|
|
358
|
-
"match": "type"
|
|
359
|
-
}
|
|
340
|
+
"queue_state": "cancelled"
|
|
360
341
|
}
|
|
361
342
|
}
|
|
362
343
|
},
|