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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36417a2faab01e0a54f959f9ce42384c79a3ea1ab6d12d7058ec36adc5cedda2
4
- data.tar.gz: 4680906b82856a6c8a6c9b52a15c90a310f48ade90326fade13d8e5875353284
3
+ metadata.gz: 91790bf0626d7e4df2d26cc1cefe89371d5bf3080bc56708775a11782f412a62
4
+ data.tar.gz: be0ce4993d12695e2b41f0b57b1860312bd52b86b2bd478973653edb994af2e8
5
5
  SHA512:
6
- metadata.gz: ad9dfe7dcacd33f965efaca4dd5edadc0ba984f802b0fa7f621e7e74764213ebeffbd36c41edfd428e2cad9f2dc7a6057459672a466f41c313a447c25c0808ed
7
- data.tar.gz: 3a14dd0bdbebd83ee3ddb7d11be9e7ef07c6e582efda353a846dd26932f6664320773e23337ffadf98245d363e6a56cb1767dee0177042869e0cdd3cb29372d6
6
+ metadata.gz: f4279fb63c5b4ba58d73f94dd342f81611af331a78b69c309d5a912c40361fc0ee4352bdb18b395ef2d7903ac38fd143236f044b34a1dea936d633f3ba214376
7
+ data.tar.gz: eec7921d963ba82888dad00cc7a3a4d93db8e8ec35044a0149aae410330a80d1503ad8d6d17543fe23a9c25826e77e2aeaf76b36a98ca00c35ffde35f84ad449
@@ -106,19 +106,7 @@ module HastCI
106
106
  context: "#{API_PATH_PREFIX}/runs/:run_id/claims"
107
107
  )
108
108
 
109
- tasks = Array(response.fetch("tasks", [])).map do |task_data|
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
@@ -2,26 +2,17 @@
2
2
 
3
3
  module HastCI
4
4
  class ClaimResult
5
- attr_reader :tasks, :queue_state, :remaining, :should_stop
5
+ attr_reader :tasks, :queue_state, :remaining
6
6
 
7
- def initialize(tasks:, queue_state:, remaining: nil, should_stop: 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
@@ -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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  # :nocov:
4
4
  module HastCI
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  # :nocov:
@@ -332,31 +332,12 @@
332
332
  }
333
333
  },
334
334
  "response": {
335
- "status": 200,
335
+ "status": 409,
336
336
  "headers": {
337
337
  "Content-Type": "application/json"
338
338
  },
339
339
  "body": {
340
- "tasks": [
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
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hastci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Wrona