withruntime 0.9.0 → 0.17.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 +4 -4
- data/lib/withruntime/agents.rb +200 -15
- data/lib/withruntime/apps.rb +141 -10
- data/lib/withruntime/builds.rb +0 -9
- data/lib/withruntime/ci.rb +156 -0
- data/lib/withruntime/client.rb +19 -2
- data/lib/withruntime/errors.rb +31 -7
- data/lib/withruntime/products.rb +110 -11
- data/lib/withruntime/record.rb +14 -0
- data/lib/withruntime/reservations.rb +76 -0
- data/lib/withruntime/sandbox.rb +53 -17
- data/lib/withruntime/transport.rb +53 -13
- data/lib/withruntime/version.rb +1 -1
- data/lib/withruntime.rb +6 -0
- metadata +4 -2
|
@@ -51,6 +51,10 @@ module WithRuntime
|
|
|
51
51
|
# could refuse (the leader drill on vin-5, 4 October 2026). It is sent
|
|
52
52
|
# again under the same key.
|
|
53
53
|
ANSWER_START = 125.0
|
|
54
|
+
# The longest wait a server names that a call sleeps on (seconds). One
|
|
55
|
+
# longer (a daily cap's hour) is raised at once, still retryable with its
|
|
56
|
+
# retry_after, for the caller to schedule.
|
|
57
|
+
LONGEST_WAIT = 60.0
|
|
54
58
|
class << self
|
|
55
59
|
attr_writer :answer_start
|
|
56
60
|
|
|
@@ -374,15 +378,22 @@ module WithRuntime
|
|
|
374
378
|
|
|
375
379
|
# Sends a call, retrying as the rules say, and returns the response once it
|
|
376
380
|
# succeeded. With a block, the body is streamed to it.
|
|
381
|
+
# +bearer+ is sent instead of the API key: a webhook trigger's secret,
|
|
382
|
+
# which is all its calls carry.
|
|
377
383
|
def send_call(http, method, path, query: nil, body: nil, raw: nil, accept: "application/json", wait: nil,
|
|
378
|
-
key: nil, no_retry: false, room:
|
|
384
|
+
key: nil, no_retry: false, room: nil, timeout: nil, cancel: nil, bearer: nil, &stream)
|
|
379
385
|
write = method != "GET"
|
|
380
386
|
key = write ? (key || SecureRandom.uuid) : nil
|
|
381
|
-
|
|
382
|
-
|
|
387
|
+
# room: nil for a call with no room wait; 0 for a create, wake, restart
|
|
388
|
+
# or fork told at once.
|
|
389
|
+
deadline = now + (timeout || @timeout) + (room || 0)
|
|
390
|
+
room_until = now + (room || 0)
|
|
383
391
|
room_attempt = 0
|
|
384
392
|
payload = raw || (body.nil? ? nil : JSON.generate(body))
|
|
385
393
|
attempt = 0
|
|
394
|
+
# An answer that ran nothing is sent again until the call's deadline
|
|
395
|
+
# (a Ruby call always has one: its timeout, plus any wait for room).
|
|
396
|
+
idle_attempt = 0
|
|
386
397
|
# The last try never left, and was sent again at once.
|
|
387
398
|
resent_at_once = false
|
|
388
399
|
loop do
|
|
@@ -391,7 +402,7 @@ module WithRuntime
|
|
|
391
402
|
raise connection_error(true, write, key) if left <= 0
|
|
392
403
|
|
|
393
404
|
request = Net::HTTPGenericRequest.new(method, !payload.nil?, true, target(path, query))
|
|
394
|
-
request["Authorization"] = "Bearer #{api_key}"
|
|
405
|
+
request["Authorization"] = "Bearer #{bearer || api_key}"
|
|
395
406
|
request["Accept"] = accept
|
|
396
407
|
request["X-Runtime-Client"] = @client
|
|
397
408
|
request["User-Agent"] = "withruntime-ruby/#{VERSION}"
|
|
@@ -497,7 +508,9 @@ module WithRuntime
|
|
|
497
508
|
{ "error" => { "message" => text.strip.empty? ? nil : text.strip[0, 500] }.compact }
|
|
498
509
|
end
|
|
499
510
|
failure = Error.from(status, parsed, key)
|
|
500
|
-
|
|
511
|
+
# A quota on what is kept says it never clears by waiting.
|
|
512
|
+
if !no_retry && room&.positive? && Error::WAITS_FOR_ROOM.include?(failure.code) && failure.details["field"] != "count" &&
|
|
513
|
+
failure.sent_retryable != false
|
|
501
514
|
room_left = room_until - now
|
|
502
515
|
raise failure if room_left <= 0
|
|
503
516
|
|
|
@@ -506,15 +519,42 @@ module WithRuntime
|
|
|
506
519
|
pause([room_left, wait_for].min, deadline, write, key, failure, cancel)
|
|
507
520
|
next
|
|
508
521
|
end
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
522
|
+
header = Float(response["Retry-After"], exception: false)
|
|
523
|
+
header = nil unless header&.positive?
|
|
524
|
+
# The wait the server names, when it names one.
|
|
525
|
+
named = failure.retry_after || header
|
|
526
|
+
# Nothing ran: safe to send again for any call, past max_retries,
|
|
527
|
+
# with growing waits, until the deadline; then this refusal stands.
|
|
528
|
+
# A late answer's failure came after the work began, so only a
|
|
529
|
+
# guest's own refusal (guest_busy, before anything is journaled)
|
|
530
|
+
# still says nothing ran.
|
|
531
|
+
if [429, 503].include?(status) && Error::NOTHING_RAN.include?(failure.code) &&
|
|
532
|
+
failure.sent_retryable != false && (!late || failure.code == "guest_busy")
|
|
533
|
+
raise failure if named && named > LONGEST_WAIT
|
|
534
|
+
|
|
535
|
+
pause_for = [30.0, (named || 0.25) * (2**[idle_attempt, 3].min)].min * (0.9 + (rand * 0.2))
|
|
536
|
+
idle_attempt += 1
|
|
537
|
+
raise failure if pause_for >= deadline - now
|
|
538
|
+
|
|
539
|
+
pause(pause_for, deadline, write, key, failure, cancel)
|
|
540
|
+
next
|
|
516
541
|
end
|
|
517
|
-
|
|
542
|
+
# The answer says whether the same call may work again; an older
|
|
543
|
+
# server that does not say is retried on 429, 502, 503 and 504. A
|
|
544
|
+
# refusal for room or the account's own limit is the room wait's on a
|
|
545
|
+
# create, wake, restart or fork; any other call retries what it says.
|
|
546
|
+
again = if failure.sent_retryable.nil?
|
|
547
|
+
[429, 502, 503, 504].include?(status) && !Error::DELIBERATE.include?(failure.code)
|
|
548
|
+
else
|
|
549
|
+
failure.sent_retryable
|
|
550
|
+
end
|
|
551
|
+
raise failure if no_retry || !again || (room && Error::WAITS_FOR_ROOM.include?(failure.code)) ||
|
|
552
|
+
attempt >= max_retries
|
|
553
|
+
# A wait longer than a minute (a daily cap) is the caller's to
|
|
554
|
+
# schedule: the error says when, in retry_after.
|
|
555
|
+
raise failure if named && named > LONGEST_WAIT
|
|
556
|
+
|
|
557
|
+
pause([30.0, named || backoff(attempt)].min * (0.9 + (rand * 0.2)), deadline, write, key, failure, cancel)
|
|
518
558
|
attempt += 1
|
|
519
559
|
end
|
|
520
560
|
end
|
data/lib/withruntime/version.rb
CHANGED
data/lib/withruntime.rb
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
# puts sbx.exec("python3 /workspace/invoice.py", check: true).stdout
|
|
12
12
|
# sbx.stop
|
|
13
13
|
#
|
|
14
|
+
# Agents are set up from a runtime.yml in your repo by the CLI, which makes
|
|
15
|
+
# the account's agents match the file: npx withruntime agents deploy. This
|
|
16
|
+
# gem has no deploy of its own.
|
|
17
|
+
#
|
|
14
18
|
# The guide is at https://withruntime.com/docs/ruby.
|
|
15
19
|
require "json"
|
|
16
20
|
require "openssl"
|
|
@@ -26,10 +30,12 @@ require_relative "withruntime/wallet"
|
|
|
26
30
|
require_relative "withruntime/tar"
|
|
27
31
|
require_relative "withruntime/sandbox"
|
|
28
32
|
require_relative "withruntime/products"
|
|
33
|
+
require_relative "withruntime/reservations"
|
|
29
34
|
require_relative "withruntime/agents"
|
|
30
35
|
require_relative "withruntime/images"
|
|
31
36
|
require_relative "withruntime/apps"
|
|
32
37
|
require_relative "withruntime/builds"
|
|
38
|
+
require_relative "withruntime/ci"
|
|
33
39
|
require_relative "withruntime/containers"
|
|
34
40
|
require_relative "withruntime/network_products"
|
|
35
41
|
require_relative "withruntime/parity_products"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: withruntime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Runtime
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'Linux sandboxes for agents, and every other Runtime Cloud product: streaming
|
|
14
14
|
commands and terminals, files and watches, images, durable volumes and backups,
|
|
@@ -24,6 +24,7 @@ files:
|
|
|
24
24
|
- lib/withruntime/api_defaults.rb
|
|
25
25
|
- lib/withruntime/apps.rb
|
|
26
26
|
- lib/withruntime/builds.rb
|
|
27
|
+
- lib/withruntime/ci.rb
|
|
27
28
|
- lib/withruntime/client.rb
|
|
28
29
|
- lib/withruntime/containers.rb
|
|
29
30
|
- lib/withruntime/credentials.rb
|
|
@@ -35,6 +36,7 @@ files:
|
|
|
35
36
|
- lib/withruntime/parity_products.rb
|
|
36
37
|
- lib/withruntime/products.rb
|
|
37
38
|
- lib/withruntime/record.rb
|
|
39
|
+
- lib/withruntime/reservations.rb
|
|
38
40
|
- lib/withruntime/sandbox.rb
|
|
39
41
|
- lib/withruntime/tar.rb
|
|
40
42
|
- lib/withruntime/transport.rb
|