hastci 0.1.1 → 0.1.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: f7d454a50c04ff233b5cb379678b92e0aeaa04f9e7b116307a7e89678fbe26be
4
- data.tar.gz: 1228b92fd4be4ba6717af33b0c0c771cb1e17315eb8648b04397d4b13ab74d6a
3
+ metadata.gz: b5b2325eb3310d82c948100ad8944303a1cafc0f3824497fa68ff3a2d229184b
4
+ data.tar.gz: 93b8a6e612a613d8491624008fa0e334653aff2b769e437385141c56ad62372b
5
5
  SHA512:
6
- metadata.gz: d731397122285e81f9bc3b410474bf7ff828b2d16f32320d2150c055e46b245a86f50a7e15f67bcd943365549de360e61783f49794db2ff901c193cb131e9ce7
7
- data.tar.gz: 7e25b68ce224aae1953c5eb797b073dc4900fad52d3537cc497543ef7cb5215d319edef657d3f6a9a6f3358d5ec5b2d8aa8f816b8f85bb672c682cb45f8b016c
6
+ metadata.gz: d8d05f307a3408f5238081361f11c5fafbf5e5f1c1eb822bbeaf8dd42fb172bc4048ca7ae6d3303aa5cf77de543f51cea829313e7efaee814c74df59680debe3
7
+ data.tar.gz: 9b557ef0c58252027907cb79197d00273e100a7735b2072203d68c897c6a966cb0b47d0d985993ebcedf2954ab1238cdab9333902352a28cdb8fd3344d0a5397
data/lib/hastci/cli.rb CHANGED
@@ -9,16 +9,22 @@ module HastCI
9
9
  runner_exit_code = ExitCodes::SUCCESS
10
10
  interrupted = false
11
11
 
12
- cleanup_result = HastCI::Session.run(config: config) do |session|
13
- setup_interrupt_handler(session, err) { interrupted = true }
12
+ interrupt_cleanup = nil
14
13
 
15
- session.start!
14
+ begin
15
+ cleanup_result = HastCI::Session.run(config: config) do |session|
16
+ interrupt_cleanup = setup_interrupt_handler(session, err) { interrupted = true }
16
17
 
17
- runner_exit_code = if session.stopping?
18
- ExitCodes::SUCCESS
19
- else
20
- runner_block.call(session, argv, err, out)
18
+ session.start!
19
+
20
+ runner_exit_code = if session.stopping?
21
+ ExitCodes::SUCCESS
22
+ else
23
+ runner_block.call(session, argv, err, out)
24
+ end
21
25
  end
26
+ ensure
27
+ interrupt_cleanup&.call
22
28
  end
23
29
 
24
30
  print_errors(cleanup_result, err: err)
@@ -81,20 +87,37 @@ module HastCI
81
87
 
82
88
  # :nocov:
83
89
  def self.setup_interrupt_handler(session, err, &on_interrupt)
84
- handler = lambda do |signal|
85
- if session.stopping?
86
- err.puts("\nForce quit!")
87
- exit!(1)
88
- else
89
- on_interrupt&.call
90
- session.request_stop!(:user_interrupt)
91
- err.puts("\nReceived #{signal} - shutting down after current task...")
90
+ signals = Queue.new
91
+ signal_count = 0
92
+
93
+ trap("INT") { signals << "SIGINT" }
94
+ trap("TERM") { signals << "SIGTERM" }
95
+
96
+ watcher = Thread.new do
97
+ loop do
98
+ signal = signals.pop
99
+ break if signal == :shutdown
100
+
101
+ already_stopping = session.stopping?
102
+ signal_count += 1
103
+
104
+ if already_stopping || signal_count > 1
105
+ err.puts("\nForce quit!")
106
+ exit!(1)
107
+ else
108
+ on_interrupt&.call
109
+ session.request_stop!(:user_interrupt)
110
+ err.puts("\nReceived #{signal} - shutting down after current task...")
111
+ end
92
112
  end
93
113
  end
94
114
 
95
- trap("INT") { handler.call("SIGINT") }
96
- trap("TERM") { handler.call("SIGTERM") }
115
+ lambda do
116
+ signals << :shutdown
117
+ watcher.join
118
+ end
97
119
  end
120
+
98
121
  private_class_method :setup_interrupt_handler
99
122
  # :nocov:
100
123
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  # :nocov:
4
4
  module HastCI
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  # :nocov:
@@ -39,14 +39,14 @@
39
39
  "Content-Type": "application/json"
40
40
  },
41
41
  "body": {
42
- "run_id": "018f1234-5678-7000-8000-123456789abc",
42
+ "run_id": "abc123def456",
43
43
  "status": "seeding",
44
44
  "role": "seeder"
45
45
  },
46
46
  "matchingRules": {
47
47
  "$.body.run_id": {
48
48
  "match": "regex",
49
- "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
49
+ "regex": "^[0-9A-Za-z_-]{12}$"
50
50
  },
51
51
  "$.body.status": {
52
52
  "match": "regex",
@@ -109,14 +109,14 @@
109
109
  "providerState": "a run exists",
110
110
  "request": {
111
111
  "method": "get",
112
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc",
112
+ "path": "/api/v1/runs/abc123def456",
113
113
  "headers": {
114
114
  "Authorization": "Bearer test-api-key"
115
115
  },
116
116
  "matchingRules": {
117
117
  "$.path": {
118
118
  "match": "regex",
119
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
119
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}$"
120
120
  }
121
121
  }
122
122
  },
@@ -141,7 +141,7 @@
141
141
  "providerState": "a run exists",
142
142
  "request": {
143
143
  "method": "post",
144
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/seed",
144
+ "path": "/api/v1/runs/abc123def456/seed",
145
145
  "headers": {
146
146
  "Authorization": "Bearer test-api-key",
147
147
  "Content-Type": "application/json"
@@ -159,7 +159,7 @@
159
159
  "matchingRules": {
160
160
  "$.path": {
161
161
  "match": "regex",
162
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/seed$"
162
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/seed$"
163
163
  }
164
164
  }
165
165
  },
@@ -179,7 +179,7 @@
179
179
  "providerState": "tasks are available",
180
180
  "request": {
181
181
  "method": "post",
182
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/claims",
182
+ "path": "/api/v1/runs/abc123def456/claims",
183
183
  "query": "batch=10",
184
184
  "headers": {
185
185
  "Authorization": "Bearer test-api-key",
@@ -191,7 +191,7 @@
191
191
  "matchingRules": {
192
192
  "$.path": {
193
193
  "match": "regex",
194
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/claims$"
194
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/claims$"
195
195
  }
196
196
  }
197
197
  },
@@ -203,19 +203,19 @@
203
203
  "body": {
204
204
  "tasks": [
205
205
  {
206
- "id": "018f1234-5678-7000-8000-123456789def",
206
+ "id": 101,
207
207
  "name": "spec/models/user_spec.rb"
208
208
  },
209
209
  {
210
- "id": "018f1234-5678-7000-8000-123456789012",
210
+ "id": 102,
211
211
  "name": "spec/models/post_spec.rb"
212
212
  },
213
213
  {
214
- "id": "018f1234-5678-7000-8000-123456789013",
214
+ "id": 103,
215
215
  "name": "spec/models/comment_spec.rb"
216
216
  },
217
217
  {
218
- "id": "018f1234-5678-7000-8000-123456789014",
218
+ "id": 104,
219
219
  "name": "spec/models/profile_spec.rb"
220
220
  }
221
221
  ],
@@ -228,20 +228,16 @@
228
228
  },
229
229
  "matchingRules": {
230
230
  "$.body.tasks[0].id": {
231
- "match": "regex",
232
- "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
231
+ "match": "type"
233
232
  },
234
233
  "$.body.tasks[1].id": {
235
- "match": "regex",
236
- "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
234
+ "match": "type"
237
235
  },
238
236
  "$.body.tasks[2].id": {
239
- "match": "regex",
240
- "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
237
+ "match": "type"
241
238
  },
242
239
  "$.body.tasks[3].id": {
243
- "match": "regex",
244
- "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
240
+ "match": "type"
245
241
  },
246
242
  "$.body.remaining.queued": {
247
243
  "match": "type"
@@ -260,7 +256,7 @@
260
256
  "providerState": "queue is empty but not drained",
261
257
  "request": {
262
258
  "method": "post",
263
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/claims",
259
+ "path": "/api/v1/runs/abc123def456/claims",
264
260
  "query": "batch=10",
265
261
  "headers": {
266
262
  "Authorization": "Bearer test-api-key",
@@ -272,7 +268,7 @@
272
268
  "matchingRules": {
273
269
  "$.path": {
274
270
  "match": "regex",
275
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/claims$"
271
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/claims$"
276
272
  }
277
273
  }
278
274
  },
@@ -288,7 +284,7 @@
288
284
  "providerState": "queue is drained",
289
285
  "request": {
290
286
  "method": "post",
291
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/claims",
287
+ "path": "/api/v1/runs/abc123def456/claims",
292
288
  "query": "batch=10",
293
289
  "headers": {
294
290
  "Authorization": "Bearer test-api-key",
@@ -300,7 +296,7 @@
300
296
  "matchingRules": {
301
297
  "$.path": {
302
298
  "match": "regex",
303
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/claims$"
299
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/claims$"
304
300
  }
305
301
  }
306
302
  },
@@ -319,7 +315,7 @@
319
315
  "providerState": "run is cancelled",
320
316
  "request": {
321
317
  "method": "post",
322
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/claims",
318
+ "path": "/api/v1/runs/abc123def456/claims",
323
319
  "query": "batch=10",
324
320
  "headers": {
325
321
  "Authorization": "Bearer test-api-key",
@@ -331,7 +327,7 @@
331
327
  "matchingRules": {
332
328
  "$.path": {
333
329
  "match": "regex",
334
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/claims$"
330
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/claims$"
335
331
  }
336
332
  }
337
333
  },
@@ -369,7 +365,7 @@
369
365
  "providerState": "a task exists",
370
366
  "request": {
371
367
  "method": "post",
372
- "path": "/api/v1/tasks/018f1234-5678-7000-8000-123456789def/acknowledgment",
368
+ "path": "/api/v1/tasks/101/acknowledgment",
373
369
  "headers": {
374
370
  "Authorization": "Bearer test-api-key",
375
371
  "Content-Type": "application/json"
@@ -386,7 +382,7 @@
386
382
  "matchingRules": {
387
383
  "$.path": {
388
384
  "match": "regex",
389
- "regex": "^\\/api\\/v1\\/tasks\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/acknowledgment$"
385
+ "regex": "^\\/api\\/v1\\/tasks\\/\\d+\\/acknowledgment$"
390
386
  }
391
387
  }
392
388
  },
@@ -405,7 +401,7 @@
405
401
  "providerState": "a worker exists",
406
402
  "request": {
407
403
  "method": "post",
408
- "path": "/api/v1/runs/018f1234-5678-7000-8000-123456789abc/heartbeats",
404
+ "path": "/api/v1/runs/abc123def456/heartbeats",
409
405
  "headers": {
410
406
  "Authorization": "Bearer test-api-key",
411
407
  "Content-Type": "application/json"
@@ -416,7 +412,7 @@
416
412
  "matchingRules": {
417
413
  "$.path": {
418
414
  "match": "regex",
419
- "regex": "^\\/api\\/v1\\/runs\\/[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\/heartbeats$"
415
+ "regex": "^\\/api\\/v1\\/runs\\/[0-9A-Za-z_-]{12}\\/heartbeats$"
420
416
  }
421
417
  }
422
418
  },
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Wrona